From 92605a9734c52db88ec6d75083ecfc671c0ba9ff Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 12 Aug 2016 10:21:41 -0700 Subject: [PATCH 1/2] Reposition textview after composition view Call the function again via setTimeout to allow changes after composition events. This prevents the IME windows jumping sometimes on thesecond key press. Fixes #208 --- src/xterm.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/xterm.js b/src/xterm.js index 88096dff..3eb4fcb0 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -302,7 +302,7 @@ * Positions the composition view on top of the cursor and the textarea just below it (so the * IME helper dialog is positioned correctly). */ - CompositionHelper.prototype.updateCompositionElements = function() { + CompositionHelper.prototype.updateCompositionElements = function(dontRecurse) { if (!this.isComposing) { return; } @@ -310,9 +310,13 @@ if (cursor) { this.compositionView.style.left = cursor.offsetLeft + 'px'; this.compositionView.style.top = cursor.offsetTop + 'px'; - this.textarea.style.left = cursor.offsetLeft + 'px'; + var compositionViewBounds = this.compositionView.getBoundingClientRect(); + this.textarea.style.left = cursor.offsetLeft + compositionViewBounds.width + 'px'; this.textarea.style.top = (cursor.offsetTop + cursor.offsetHeight) + 'px'; } + if (!dontRecurse) { + setTimeout(this.updateCompositionElements.bind(this, true), 0); + } }; /** From c24ae84b00713bb426082dab28ecda4330b88ab0 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 12 Aug 2016 10:27:49 -0700 Subject: [PATCH 2/2] Fix tests --- test/composition-helper-test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/composition-helper-test.js b/test/composition-helper-test.js index ceb2b4ea..2f2ba5f1 100644 --- a/test/composition-helper-test.js +++ b/test/composition-helper-test.js @@ -14,6 +14,9 @@ describe('CompositionHelper', function () { add: function () {}, remove: function () {}, }, + getBoundingClientRect: function () { + return { width: 0 } + }, style: { left: 0, top: 0