Skip to content

Commit

Permalink
fix(tab character insertion): Key#isTab is false if a modifier key is…
Browse files Browse the repository at this point in the history
… pressed (#566)

Fixes #565
  • Loading branch information
bantic authored Jul 27, 2017
1 parent 26364f4 commit ecf5912
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/js/utils/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,14 @@ const Key = class Key {
return this.keyCode === Keycodes.SPACE;
}

// In Firefox, pressing ctrl-TAB will switch to another open browser tab, but it will
// also fire a keydown event for the tab+modifier (ctrl). This causes Mobiledoc
// to erroneously insert a tab character before FF switches to the new browser tab.
// Chrome doesn't fire this event so the issue doesn't arise there.
// Fix this by returning false when the TAB key event includes a modifier.
// See: https://github.com/bustle/mobiledoc-kit/issues/565
isTab() {
return this.keyCode === Keycodes.TAB;
return !this.hasAnyModifier() && this.keyCode === Keycodes.TAB;
}

isEnter() {
Expand Down
10 changes: 10 additions & 0 deletions tests/acceptance/editor-input-handlers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Helpers from '../test-helpers';
import Range from 'mobiledoc-kit/utils/cursor/range';
import { NO_BREAK_SPACE } from 'mobiledoc-kit/renderers/editor-dom';
import { TAB } from 'mobiledoc-kit/utils/characters';
import { MODIFIERS } from 'mobiledoc-kit/utils/key';

const { module, test } = Helpers;
const { editor: { buildFromText } } = Helpers;
Expand Down Expand Up @@ -300,6 +301,15 @@ test('input handler can be triggered by TAB', (assert) => {
assert.ok(didMatch);
});

// See https://github.com/bustle/mobiledoc-kit/issues/565
test('typing ctrl-TAB does not insert TAB text', (assert) => {
editor = Helpers.editor.buildFromText('abc|', {element: editorElement});

Helpers.dom.triggerKeyCommand(editor, TAB, [MODIFIERS.CTRL]);

assert.equal(editorElement.textContent, 'abc', 'no TAB is inserted');
});

test('can unregister all handlers', (assert) => {
editor = Helpers.editor.buildFromText('');
// there are 3 default helpers
Expand Down

0 comments on commit ecf5912

Please sign in to comment.