diff --git a/src/xterm.js b/src/xterm.js index d3b500ae..416422c5 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -232,7 +232,16 @@ // Ensure that the input has not already been sent if (self.isSendingComposition) { self.isSendingComposition = false; - var input = self.textarea.value.substring(currentCompositionPosition.start, currentCompositionPosition.end); + var input; + if (self.isComposing) { + // Use the end position to get the string if a new composition has started. + input = self.textarea.value.substring(currentCompositionPosition.start, currentCompositionPosition.end); + } else { + // Don't use the end position here in order to pick up any characters after the + // composition has finished, for example when typing a non-composition character + // (eg. 2) after a composition character. + input = self.textarea.value.substring(currentCompositionPosition.start); + } self.terminal.handler(input); } }, 0); diff --git a/test/composition-helper-test.js b/test/composition-helper-test.js index 502d72cf..558bcdff 100644 --- a/test/composition-helper-test.js +++ b/test/composition-helper-test.js @@ -21,7 +21,11 @@ describe('CompositionHelper', function () { textContent: '' } textarea = { - value: '' + value: '', + style: { + left: 0, + top: 0 + } } terminal = { element: { @@ -54,8 +58,8 @@ describe('CompositionHelper', function () { it('should define CompositionHelper.prototype.handleAnyTextareaChanges', function () { assert.isDefined(Terminal.CompositionHelper.prototype.handleAnyTextareaChanges); }); - it('should define CompositionHelper.prototype.updateCompositionViewPosition', function () { - assert.isDefined(Terminal.CompositionHelper.prototype.updateCompositionViewPosition); + it('should define CompositionHelper.prototype.updateCompositionElements', function () { + assert.isDefined(Terminal.CompositionHelper.prototype.updateCompositionElements); }); it('should define CompositionHelper.isComposing', function () { assert.isDefined(compositionHelper.isComposing); @@ -166,5 +170,21 @@ describe('CompositionHelper', function () { it('Should insert multi-line charcters that are converted to other characters', function () { // TODO: Implement a hiragana -> kanji example }); + + it('Should insert non-composition charcters input immediately after composition characters', function () { + // First character + compositionHelper.compositionstart(); + compositionHelper.compositionupdate({ data: 'ㅇ' }); + textarea.value = 'ㅇ'; + setTimeout(function() { // wait for any textarea updates + compositionHelper.compositionend(); + // Second character is non-composition character (1) + textarea.value = 'ㅇ1'; + setTimeout(function() { // wait for any textarea updates + assert.equal(handledText, 'ㅇ1'); + done(); + }, 0); + }, 0); + }); }); });