diff --git a/src/js/selection/SelectionManager.js b/src/js/selection/SelectionManager.js index 8d8b897f..dfb21cbf 100644 --- a/src/js/selection/SelectionManager.js +++ b/src/js/selection/SelectionManager.js @@ -26,6 +26,7 @@ pskl.app.shortcutService.registerShortcut(shortcuts.SELECTION.CUT, this.cut.bind(this)); pskl.app.shortcutService.registerShortcut(shortcuts.SELECTION.COPY, this.copy.bind(this)); pskl.app.shortcutService.registerShortcut(shortcuts.SELECTION.DELETE, this.onDeleteShortcut_.bind(this)); + pskl.app.shortcutService.registerShortcut(shortcuts.SELECTION.COMMIT, this.commit.bind(this)); $.subscribe(Events.TOOL_SELECTED, $.proxy(this.onToolSelected_, this)); }; @@ -110,6 +111,19 @@ }); }; + /** + * If the currently selected tool is a selection tool, call dismissSelection handler on + * the current tool instance. + */ + ns.SelectionManager.prototype.commit = function() { + var tool = pskl.app.drawingController.currentToolBehavior; + var isSelectionTool = tool instanceof pskl.tools.drawing.selection.BaseSelect; + if (isSelectionTool) { + var overlay = pskl.app.drawingController.overlayFrame; + tool.dismissSelection(overlay); + } + }; + ns.SelectionManager.prototype.replay = function (frame, replayData) { if (replayData.type === SELECTION_REPLAY.PASTE) { this.pastePixels_(frame, replayData.pixels); diff --git a/src/js/service/keyboard/KeycodeTranslator.js b/src/js/service/keyboard/KeycodeTranslator.js index b5156897..7cd8a293 100644 --- a/src/js/service/keyboard/KeycodeTranslator.js +++ b/src/js/service/keyboard/KeycodeTranslator.js @@ -1,7 +1,7 @@ (function () { var specialKeys = { - 191 : '?', 8 : 'back', + 13 : 'enter', 27 : 'esc', 37 : 'left', 38 : 'up', @@ -20,6 +20,7 @@ 61 : '+', 188 : '<', 190 : '>', + 191 : '?', 219 : '[', 221 : ']' }; diff --git a/src/js/service/keyboard/Shortcut.js b/src/js/service/keyboard/Shortcut.js index beee43c0..31b934f6 100644 --- a/src/js/service/keyboard/Shortcut.js +++ b/src/js/service/keyboard/Shortcut.js @@ -53,7 +53,18 @@ * @return {Boolean} true if the shortcut can be updated */ ns.Shortcut.prototype.isEditable = function () { - return this.getKeys().length < 2; + if (this.getKeys().length === 0) { + // No key defined: can be edited. + return true; + } + + if (this.getKeys().length === 1) { + // Only one key defined, can be edited if it is not using a forbidden key. + return ns.Shortcuts.FORBIDDEN_KEYS.indexOf(this.getKeys()[0]) === -1; + } + + // More than one key, can't be edited. + return false; }; ns.Shortcut.prototype.isCustom = function () { diff --git a/src/js/service/keyboard/Shortcuts.js b/src/js/service/keyboard/Shortcuts.js index 70151fea..c0dc7369 100644 --- a/src/js/service/keyboard/Shortcuts.js +++ b/src/js/service/keyboard/Shortcuts.js @@ -11,7 +11,7 @@ * Or really custom shortcuts such as the 1-9 for color palette shorctus */ FORBIDDEN_KEYS : ['1', '2', '3', '4', '5', '6', '7', '8', '9', '?', 'shift+?', - 'del', 'back', 'ctrl+Y', 'ctrl+shift+Z'], + 'DEL', 'BACK', 'ENTER', 'ctrl+Y', 'ctrl+shift+Z'], /** * Syntax : createShortcut(id, description, default key(s)) @@ -38,7 +38,8 @@ CUT : createShortcut('selection-cut', 'Cut selection', 'ctrl+X'), COPY : createShortcut('selection-copy', 'Copy selection', 'ctrl+C'), PASTE : createShortcut('selection-paste', 'Paste selection', 'ctrl+V'), - DELETE : createShortcut('selection-delete', 'Delete selection', ['del', 'back']) + DELETE : createShortcut('selection-delete', 'Delete selection', ['DEL', 'BACK']), + COMMIT : createShortcut('selection-commit', 'Commit selection', ['ENTER']) }, MISC : { diff --git a/src/js/tools/drawing/selection/BaseSelect.js b/src/js/tools/drawing/selection/BaseSelect.js index e6b2ffda..6999dfd0 100644 --- a/src/js/tools/drawing/selection/BaseSelect.js +++ b/src/js/tools/drawing/selection/BaseSelect.js @@ -23,7 +23,8 @@ this.tooltipDescriptors = [ {description : 'Drag the selection to move it. You may switch to other layers and frames.'}, {key : 'ctrl+c', description : 'Copy the selected area'}, - {key : 'ctrl+v', description : 'Paste the copied area'} + {key : 'ctrl+v', description : 'Paste the copied area'}, + {key : 'shift', description : 'Hold to move the content'} ]; }; @@ -52,6 +53,7 @@ if (event.shiftKey && !this.isMovingContent_) { this.isMovingContent_ = true; $.publish(Events.SELECTION_CUT); + this.drawSelectionOnOverlay_(overlay); } this.onSelectionMoveStart_(col, row, frame, overlay); }