Skip to content

Commit

Permalink
bugfix: global shortcuts (like CTRL+A) should be blocked when cell is…
Browse files Browse the repository at this point in the history
… being edited
  • Loading branch information
warpech committed Feb 28, 2013
1 parent 463d5c9 commit 8363008
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Bugfixes:
- copy/paste did not work on Mac since 0.8.6 ([#348](https://github.com/warpech/jquery-handsontable/issues/348)
- global shortcuts (like CTRL+A) should be blocked when cell is being edited

## [0.8.6](https://github.com/warpech/jquery-handsontable/tree/v0.8.6) (Feb 27, 2013)

Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.handsontable.full.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Thu Feb 28 2013 13:05:52 GMT+0100 (Central European Standard Time)
* Date: Thu Feb 28 2013 14:20:04 GMT+0100 (Central European Standard Time)
*/

.handsontable {
Expand Down
9 changes: 3 additions & 6 deletions dist/jquery.handsontable.full.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Thu Feb 28 2013 13:05:52 GMT+0100 (Central European Standard Time)
* Date: Thu Feb 28 2013 14:20:04 GMT+0100 (Central European Standard Time)
*/
/*jslint white: true, browser: true, plusplus: true, indent: 4, maxerr: 50 */

Expand Down Expand Up @@ -2731,11 +2731,8 @@ HandsontableTextEditorClass.prototype.bindEvents = function () {
event.preventDefault(); //don't add newline to field
break;

case 8: /* backspace */
case 46: /* delete */
case 36: /* home */
case 35: /* end */
event.stopPropagation();
default:
event.stopPropagation(); //backspace, delete, home, end, CTRL+A, CTRL+C, CTRL+V, CTRL+X should only work locally when cell is edited (not in table context)
break;
}
});
Expand Down
2 changes: 1 addition & 1 deletion jquery.handsontable.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Thu Feb 28 2013 13:05:52 GMT+0100 (Central European Standard Time)
* Date: Thu Feb 28 2013 14:20:04 GMT+0100 (Central European Standard Time)
*/

.handsontable {
Expand Down
9 changes: 3 additions & 6 deletions jquery.handsontable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Thu Feb 28 2013 13:05:52 GMT+0100 (Central European Standard Time)
* Date: Thu Feb 28 2013 14:20:04 GMT+0100 (Central European Standard Time)
*/
/*jslint white: true, browser: true, plusplus: true, indent: 4, maxerr: 50 */

Expand Down Expand Up @@ -2731,11 +2731,8 @@ HandsontableTextEditorClass.prototype.bindEvents = function () {
event.preventDefault(); //don't add newline to field
break;

case 8: /* backspace */
case 46: /* delete */
case 36: /* home */
case 35: /* end */
event.stopPropagation();
default:
event.stopPropagation(); //backspace, delete, home, end, CTRL+A, CTRL+C, CTRL+V, CTRL+X should only work locally when cell is edited (not in table context)
break;
}
});
Expand Down
7 changes: 2 additions & 5 deletions src/editors/textEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,8 @@ HandsontableTextEditorClass.prototype.bindEvents = function () {
event.preventDefault(); //don't add newline to field
break;

case 8: /* backspace */
case 46: /* delete */
case 36: /* home */
case 35: /* end */
event.stopPropagation();
default:
event.stopPropagation(); //backspace, delete, home, end, CTRL+A, CTRL+C, CTRL+V, CTRL+X should only work locally when cell is edited (not in table context)
break;
}
});
Expand Down
9 changes: 5 additions & 4 deletions test/jasmine/spec/SpecHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var contextMenu = function () {
* @return {Function}
*/
var handsontableKeyTriggerFactory = function (type) {
return function (key) {
return function (key, extend) {
var ev = $.Event(type);
if (typeof key === 'string') {
if (key.indexOf('shift+') > -1) {
Expand Down Expand Up @@ -129,6 +129,7 @@ var handsontableKeyTriggerFactory = function (type) {
else if (typeof key === 'number') {
ev.keyCode = key;
}
$.extend(ev, extend);
$(document.activeElement).trigger(ev);
}
};
Expand All @@ -139,9 +140,9 @@ var keyUp = handsontableKeyTriggerFactory('keyup');
/**
* Presses keyDown, then keyUp
*/
var keyDownUp = function (key) {
keyDown(key);
keyUp(key);
var keyDownUp = function (key, extend) {
keyDown(key, extend);
keyUp(key, extend);
};

/**
Expand Down
23 changes: 23 additions & 0 deletions test/jasmine/spec/editors/textEditorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,27 @@ describe('TextEditor', function () {
expect(keyProxy().width()).toEqual($td.width());
});
});

it('global shortcuts (like CTRL+A) should be blocked when cell is being edited', function () {
handsontable();
selectCell(2, 2);

waitsFor(nextFrame, 'next frame', 60);

runs(function () {
keyDownUp('enter');
});

waitsFor(nextFrame, 'next frame', 60);

runs(function () {
keyDown(65, {ctrlKey: true}); //CTRL+A should NOT select all table when cell is edited
});

runs(function () {
var selection = getSelected();
expect(selection).toEqual([2, 2, 2, 2]);
expect(isEditorVisible()).toEqual(true);
});
});
});

0 comments on commit 8363008

Please sign in to comment.