-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Suppress mutations when using an IME on a blank line * Ignore control keydowns when IME is active * Handle carriage return keypresses
- Loading branch information
Showing
4 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import Keycodes from 'mobiledoc-kit/utils/keycodes'; | ||
import Browser from 'mobiledoc-kit/utils/browser'; | ||
import Helpers from '../test-helpers'; | ||
|
||
let editor, editorElement; | ||
|
||
const { test, module } = Helpers; | ||
|
||
module('Acceptance: editor: IME Composition Event Handler', { | ||
beforeEach() { | ||
editorElement = $('#editor')[0]; | ||
}, | ||
afterEach() { | ||
if (editor) { editor.destroy(); } | ||
} | ||
}); | ||
|
||
['Enter', 'Tab', 'Backspace'].forEach((key) => { | ||
test(`ignore ${key} keydowns when using an IME`, (assert) => { | ||
let { post: expected } = Helpers.postAbstract.buildFromText('你好'); | ||
editor = Helpers.editor.buildFromText('你好', { element: editorElement }); | ||
|
||
Helpers.dom.moveCursorTo(editor, editorElement.firstChild, 1); | ||
|
||
Helpers.dom.triggerKeyEvent(editor, 'keydown', { | ||
key, | ||
keyCode: Keycodes.IME, | ||
charCode: Keycodes[key.toUpperCase()] | ||
}); | ||
|
||
assert.postIsSimilar(editor.post, expected); | ||
}); | ||
}); | ||
|
||
test('ignore horizontal arrow keydowns when using IME', (assert) => { | ||
editor = Helpers.editor.buildFromText("안녕하세요", { element: editorElement }); | ||
|
||
Helpers.dom.moveCursorTo(editor, editorElement.firstChild); | ||
|
||
Helpers.dom.triggerKeyEvent(editor, 'keydown', { | ||
key: 'ArrowRight', | ||
keyCode: Keycodes.IME, | ||
charCode: Keycodes.RIGHT | ||
}); | ||
|
||
assert.positionIsEqual(editor.range.head, editor.post.headPosition()); | ||
|
||
Helpers.dom.moveCursorTo(editor, editorElement.firstChild, 1); | ||
|
||
Helpers.dom.triggerKeyEvent(editor, 'keydown', { | ||
key: 'ArrowLeft', | ||
keyCode: Keycodes.IME, | ||
charCode: Keycodes.LEFT | ||
}); | ||
|
||
assert.positionIsEqual(editor.range.head, editor.post.tailPosition()); | ||
}); | ||
|
||
// There doesn't seem to be a way to directly test the usage | ||
// of an OS-level IME, however this test roughly simulates | ||
// how the IME inputs text into the DOM. | ||
test('test handling of IME composition events', (assert) => { | ||
let done = assert.async(); | ||
|
||
editor = Helpers.editor.buildFromText("", { element: editorElement }); | ||
|
||
Helpers.dom.moveCursorTo(editor, editorElement); | ||
|
||
editor.element.dispatchEvent( | ||
new CompositionEvent('compositionstart', { 'data': 'n' }) | ||
); | ||
|
||
Helpers.wait(() => { | ||
if(Browser.isChrome()) { | ||
editorElement.firstChild.innerHTML = "こんにちは" | ||
} else { | ||
editorElement.firstChild.innerHTML += "こんにちは" | ||
} | ||
|
||
Helpers.wait(() => { | ||
editor.element.dispatchEvent( | ||
new CompositionEvent('compositionend', { 'data': 'こんにちは' }) | ||
); | ||
|
||
Helpers.wait(() => { | ||
assert.positionIsEqual(editor.range.head, editor.post.tailPosition()); | ||
assert.hasElement('#editor p:contains(こんにちは)'); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |