From a019dc34c39e7f89a53ba3b8adb82f041f7aa1ad Mon Sep 17 00:00:00 2001 From: Zachary Yaro Date: Thu, 26 Nov 2015 22:44:03 -0500 Subject: [PATCH] Delete the current selection when Delete or Backspace is pressed --- app/scripts/keyboard.js | 12 ++++++++++++ app/scripts/tools/selection.js | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/scripts/keyboard.js b/app/scripts/keyboard.js index 2c15383c..2fd7f77e 100644 --- a/app/scripts/keyboard.js +++ b/app/scripts/keyboard.js @@ -1,6 +1,18 @@ var keyManager = { _keyPressListener: function (e) { switch (e.keyCode) { + case 8: // Backspace + if (localStorage.tool === 'selection') { + e.preventDefault(); + tools.selection.clear(); + } + break; + case 46: // Delete + if (localStorage.tool === 'selection') { + e.preventDefault(); + tools.selection.clear(); + } + break; case 65: // A if (e.ctrlKey) { e.preventDefault(); diff --git a/app/scripts/tools/selection.js b/app/scripts/tools/selection.js index 71bf85de..39aec21e 100644 --- a/app/scripts/tools/selection.js +++ b/app/scripts/tools/selection.js @@ -120,6 +120,23 @@ SelectionTool.prototype.deactivate = function () { }; +/** + * Delete the currently selected content. + */ +SelectionTool.prototype.clear = function () { + // Quit if there is no selection to delete. + if (!this._selection) { + return; + } + + this._cxt.fillStyle = localStorage.fillColor; + this._cxt.fillRect(this._selection.startX, this._selection.startY, + this._selection.width, this._selection.height); + Utils.clearCanvas(this._preCxt); + undoStack.addState(); + delete this._selection; +}; + /** * Drop the current selection and create a duplicate at (0,0). */