Skip to content

Commit

Permalink
Delete the current selection when Delete or Backspace is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
ZMYaro committed Nov 27, 2015
1 parent 698e4f2 commit a019dc3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/scripts/keyboard.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
17 changes: 17 additions & 0 deletions app/scripts/tools/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*/
Expand Down

0 comments on commit a019dc3

Please sign in to comment.