From d8e2bc31290849a4753e779cb91d49df85d38032 Mon Sep 17 00:00:00 2001 From: Zhenlei Jia Date: Thu, 11 Jul 2019 08:38:51 -0400 Subject: [PATCH] 1. The underlying textarea now listens to "input" event, and update the content of target morphic accordingly. 2. The textarea still listens to "keydown" and "keyup" events, for the following puerpose: "keydown" event handler will detech some system shortcuts, add will pass it to "the world". "keyup" event handler is used to capture the change of selection status and cursor position of the textarea (which is not captured in the above "input" event), and update the target morphic. --- src/morphic.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/morphic.js b/src/morphic.js index 5d38243f..11217b14 100644 --- a/src/morphic.js +++ b/src/morphic.js @@ -5421,7 +5421,7 @@ CursorMorph.prototype.initializeTextarea = function () { // For other keyboard events, first let the textarea element handle the // events, then we take its state and update the target morph and cursor // morph accordingly. - this.textarea.addEventListener('keyup', function (event) { + this.textarea.addEventListener('input', function (event) { myself.world().currentKey = null; var target = myself.target; @@ -5461,6 +5461,7 @@ CursorMorph.prototype.initializeTextarea = function () { } // target morph: copy the content and selection status to the target. target.text = filteredContent; + if (textarea.selectionStart === textarea.selectionEnd) { target.startMark = null; target.endMark = null; @@ -5481,7 +5482,29 @@ CursorMorph.prototype.initializeTextarea = function () { myself.gotoSlot(textarea.selectionStart); myself.updateTextAreaPosition(); - target.escalateEvent('reactToKeystroke', event); + //target.escalateEvent('reactToKeystroke', event); + }); + + this.textarea.addEventListener('keyup', function (event) { + var textarea = myself.textarea; + var target = myself.target; + + if (textarea.selectionStart === textarea.selectionEnd) { + target.startMark = null; + target.endMark = null; + } else { + if (textarea.selectionDirection === 'backward') { + target.startMark = textarea.selectionEnd; + target.endMark = textarea.selectionStart; + } else { + target.startMark = textarea.selectionStart; + target.endMark = textarea.selectionEnd; + } + } + target.changed(); + target.drawNew(); + target.changed(); + myself.gotoSlot(textarea.selectionEnd); }); };