]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/static/js/editor.js
wiki: Add keyboard shortcuts to edit text
[ipfire.org.git] / src / static / js / editor.js
index 39fac6b214c0b91e4986cf6da60c4c0d3289c245..6311f8706ab5065b32f173d2c757e22aac0466ef 100644 (file)
@@ -19,6 +19,11 @@ class Editor {
 
         // Remember any selected text
         this.textarea.on("select keyup click", function(e) {
+            // Ignore any keyboard shortcuts
+            if (e.ctrlKey)
+                return;
+
+            // Save selected text
             editor.selection = {
                 start : this.selectionStart,
                 end   : this.selectionEnd,
@@ -29,6 +34,30 @@ class Editor {
             console.debug("Something got selected:");
             console.debug(editor.selection);
         })
+
+        // Bind keyboard shortcuts
+        this.textarea.on("keyup", function(e) {
+            // If Ctrl wasn't pressed this isn't for us
+            if (!e.ctrlKey)
+                return;
+
+            switch (e.which) {
+                // B - Bold
+                case 66:
+                    editor.bold();
+                    break;
+
+                // I - Italic
+                case 73:
+                    editor.italic();
+                    break;
+
+                // H - Headline
+                case 72:
+                    editor.headline();
+                    break;
+            }
+        });
     }
 
     bindKeys() {