Skip to content

Commit

Permalink
Merge pull request #653 from daviferreira/button-shift-key
Browse files Browse the repository at this point in the history
Don't execute button shortcut when shift key is pressed
  • Loading branch information
nmielnik committed May 29, 2015
2 parents ae9835a + 883734e commit d6053e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions spec/buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ describe('Buttons TestCase', function () {
});
expect(editor.execAction).toHaveBeenCalled();
});

it('should not execute the button action when shift key is pressed', function () {
spyOn(MediumEditor.prototype, 'execAction');
var editor = this.newMediumEditor('.editor'),
code = 'b'.charCodeAt(0);
selectElementContentsAndFire(editor.elements[0]);
jasmine.clock().tick(1);
fireEvent(editor.elements[0], 'keydown', {
keyCode: code,
ctrlKey: true,
metaKey: true,
shiftKey: true
});
expect(editor.execAction).not.toHaveBeenCalled();
});
});

describe('Buttons with various labels', function () {
Expand Down
4 changes: 2 additions & 2 deletions src/js/extensions/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var Button;
handleKeydown: function (event) {
var action;

if (Util.isKey(event, this.key.charCodeAt(0)) && Util.isMetaCtrlKey(event)) {
if (Util.isKey(event, this.key.charCodeAt(0)) && Util.isMetaCtrlKey(event) && !event.shiftKey) {
event.preventDefault();
event.stopPropagation();

Expand Down Expand Up @@ -139,4 +139,4 @@ var Button;
return isMatch;
}
});
}());
}());

0 comments on commit d6053e2

Please sign in to comment.