diff --git a/src/editor.js b/src/editor.js index 5a8d0728..e3ca51bf 100644 --- a/src/editor.js +++ b/src/editor.js @@ -59,9 +59,15 @@ // Whether the rich text editor should be rendered on touch devices (wysihtml5 >= 0.3.0 comes with basic support for iOS 5) supportTouchDevices: true, // Whether senseless elements (empty or without attributes) should be removed/replaced with their content - cleanUp: true + cleanUp: true, + // Set default keyboard shortcuts but allow developer to override + shortcuts: { + "66": "bold", // B + "73": "italic", // I + "85": "underline" // U + } }; - + wysihtml5.Editor = wysihtml5.lang.Dispatcher.extend( /** @scope wysihtml5.Editor.prototype */ { constructor: function(textareaElement, config) { diff --git a/src/views/composer.observe.js b/src/views/composer.observe.js index 472308d4..3ead77f4 100644 --- a/src/views/composer.observe.js +++ b/src/views/composer.observe.js @@ -12,11 +12,7 @@ /** * Map keyCodes to query commands */ - shortcuts = { - "66": "bold", // B - "73": "italic", // I - "85": "underline" // U - }; + shortcuts = {}; wysihtml5.views.Composer.prototype.observe = function() { var that = this, @@ -24,7 +20,8 @@ iframe = this.sandbox.getIframe(), element = this.element, focusBlurElement = browser.supportsEventsInIframeCorrectly() ? element : this.sandbox.getWindow(), - pasteEvents = ["drop", "paste"]; + pasteEvents = ["drop", "paste"], + shortcuts = that.commands.editor.config.shortcuts; // --------- destroy:composer event --------- dom.observe(iframe, "DOMNodeRemoved", function() { @@ -121,9 +118,16 @@ // --------- Shortcut logic --------- dom.observe(element, "keydown", function(event) { var keyCode = event.keyCode, - command = shortcuts[keyCode]; + shiftModifyer = event.shiftKey ? "shift+" : "", + command = shortcuts[shiftModifyer+keyCode]; if ((event.ctrlKey || event.metaKey) && !event.altKey && command) { - that.commands.exec(command); + var commandObj = that.commands.editor.toolbar.commandMapping[command + ":null"]; + // Show dialog when available + if (commandObj && commandObj.dialog && !commandObj.state) { + commandObj.dialog.show(); + } else { + that.commands.exec(command); + } event.preventDefault(); } });