From 646f9732f38c80cb631af4b421bca7ef4051960f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 17 Dec 2017 21:51:19 -0800 Subject: [PATCH] GUACAMOLE-352: Track in-progress composition, ignoring "input" events for a composition which is known to be incomplete. --- .../src/main/webapp/modules/Keyboard.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/guacamole-common-js/src/main/webapp/modules/Keyboard.js b/guacamole-common-js/src/main/webapp/modules/Keyboard.js index 4c4b1bad9..1df14e20f 100644 --- a/guacamole-common-js/src/main/webapp/modules/Keyboard.js +++ b/guacamole-common-js/src/main/webapp/modules/Keyboard.js @@ -1231,6 +1231,15 @@ Guacamole.Keyboard = function(element) { }; + /** + * The in-progress composition, if any, such as the intermediate result of + * pressing a series of dead keys. + * + * @private + * @type {String} + */ + var inProgressComposition = ''; + /** * Handles the given "input" event, typing the data within the input text. * If the event is complete (text is provided), handling of "compositionend" @@ -1245,6 +1254,11 @@ Guacamole.Keyboard = function(element) { // Only intercept if handler set if (!guac_keyboard.onkeydown && !guac_keyboard.onkeyup) return; + // Ignore input events which represent the in-progress composition, + // as reported by composition events + if (e.data === inProgressComposition) + return; + // Type all content written if (e.data && isComposed(e.data)) { element.removeEventListener("compositionend", handleComposition, false); @@ -1280,6 +1294,14 @@ Guacamole.Keyboard = function(element) { element.addEventListener("input", handleInput, false); element.addEventListener("compositionend", handleComposition, false); + element.addEventListener("compositionstart", function resetComposition() { + inProgressComposition = ''; + }, false); + + element.addEventListener("compositionupdate", function updateComposition(e) { + inProgressComposition = e.data; + }, false); + }; /**