From 5bdad135ca207700c2e6db96552601ac5df4f970 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Mon, 14 Oct 2019 12:51:03 +0200 Subject: [PATCH] added new "reactToInput" text-editing event to Morphic to address timing conflicts between "reactToKeystroke", which new gets triggeref before the input actually changes. --- HISTORY.md | 3 +++ snap.html | 2 +- src/morphic.js | 19 +++++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index c114ce63..a58e574f 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -15,6 +15,9 @@ * Galician, thanks, Bernat * Turkish, thanks, Turgut! +### 2019-10-14 +* morphic: new "reactToInput" text-editing event + ### 2019-10-11 * objects, threads: accept a list of pixels in the SWITCH TO COSTUME block diff --git a/snap.html b/snap.html index f2bbc581..7d3c8f12 100755 --- a/snap.html +++ b/snap.html @@ -4,7 +4,7 @@ Snap! Build Your Own Blocks 5.1.1 - dev - - + diff --git a/src/morphic.js b/src/morphic.js index ec57fa69..07a91f14 100644 --- a/src/morphic.js +++ b/src/morphic.js @@ -760,13 +760,24 @@ events: Whenever the user presses a key on the keyboard while a text element - is being edited, a + is being edited, first a reactToKeystroke(event) is escalated up its parent chain, the "event" parameter being the original one received by the World. + Whenever the input changes, by adding or removing one or more characters, + an additional + + reactToInput(event) + + is escalated up its parent chain, the "event" parameter again being the + original one received by the World or by the IME element. + + Note that the "reactToKeystroke" event gets triggered before the input + changes, and thus befgore the "reactToInput" event fires. + Once the user has completed the edit, the following events are dispatched: @@ -1166,7 +1177,7 @@ /*global window, HTMLCanvasElement, FileReader, Audio, FileList, Map*/ -var morphicVersion = '2019-October-09'; +var morphicVersion = '2019-October-14'; var modules = {}; // keep track of additional loaded modules var useBlurredShadows = getBlurredShadowSupport(); // check for Chrome-bug @@ -5534,6 +5545,10 @@ CursorMorph.prototype.initializeTextarea = function () { myself.gotoSlot(textarea.selectionStart); myself.updateTextAreaPosition(); + + // the "reactToInput" event gets triggered AFTER "reactToKeystroke" + myself.target.escalateEvent('reactToInput', event); + }); this.textarea.addEventListener('keyup', function (event) {