RichTextEditor Demo
Home Pricing

## Keyboard Shortcuts

General Shortcuts (CTRL+Z,A,X,C,V,B,U,I) are supported in Rich Text Editor. You can also create your own keyboard shortcuts.

This demo shows how to create two shortcuts (CTRL+J and Ctrl+Down Arrow).

### Demo Code:

    import { createRichTextEditor } from "ts-rich-text-editor";

    const editor = await createRichTextEditor("#div_editor1", {}, {
      basePath: "/richtexteditor",
    });

    editor.document.addEventListener("keydown", (e: KeyboardEvent) => {
      if (e.ctrlKey && e.key === "j") {
        e.preventDefault();
        editor.insertHTML("&nbsp;" + new Date().toString() + "&nbsp;");
        editor.collapse(false);
      }
      if (e.ctrlKey && e.keyCode === 40) {
        e.preventDefault();
        editor.selectDoc(false);
        const p = editor.insertRootParagraph("p");
        p.innerHTML = "<br/>";
        editor.selectDoc(false);
      }
    });

    <link rel="stylesheet" href="/richtexteditor/rte_theme_default.css" />
    <script type="text/javascript" src="/richtexteditor/rte.js"></script>
    <script type="text/javascript" src='/richtexteditor/plugins/all_plugins.js'></script>
    <div id="div_editor1"><p>This demo shows how to create two shortcuts (CTRL+J and Ctrl+Down Arrow).<p></div>
    <script>
    	var editor1 = new RichTextEditor("#div_editor1");
    	editor1.document.addEventListener("keydown", function (e) {
    		if (e.ctrlKey && e.key == 'j') {
    			e.preventDefault();
    			editor1.insertHTML("&nbsp;" + new Date().toString() + "&nbsp;");
    			editor1.collapse(false);
    		}
    		if (e.ctrlKey && e.keyCode == 40) {//ArrowDown
    			e.preventDefault();
    			editor1.selectDoc(false);
    			var p = editor1.insertRootParagraph("p");
    			p.innerHTML = "<br/>";
    			editor1.selectDoc(false);
    		}
    	})
    </script>