From 376c4380d5fc7bb61134b0a513d52b101b7bee4c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 18 Dec 2017 16:29:54 -0800 Subject: [PATCH] GUACAMOLE-352: Monitor input and composition events to keep input sink contents clear. --- .../src/main/webapp/modules/Keyboard.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/guacamole-common-js/src/main/webapp/modules/Keyboard.js b/guacamole-common-js/src/main/webapp/modules/Keyboard.js index 61889c1dc..6874e0a07 100644 --- a/guacamole-common-js/src/main/webapp/modules/Keyboard.js +++ b/guacamole-common-js/src/main/webapp/modules/Keyboard.js @@ -1448,20 +1448,22 @@ Guacamole.Keyboard.InputSink = function InputSink() { field.style.left = '-10px'; field.style.top = '-10px'; - /** - * Clears the contents of the underlying field. The actual clearing of the - * field is deferred, occurring asynchronously after the call completes. - * - * @private - */ - var clear = function clear() { - window.setTimeout(function deferClear() { - field.value = ''; - }, 0); - }; + // Keep field clear when modified via normal keypresses + field.addEventListener("keypress", function clearKeypress(e) { + field.value = ''; + }, false); - // Keep internal field contents clear - field.addEventListener("change", clear, false); + // Keep field clear when modofied via composition events + field.addEventListener("compositionend", function clearCompletedComposition(e) { + if (e.data) + field.value = ''; + }, false); + + // Keep field clear when modofied via input events + field.addEventListener("input", function clearCompletedInput(e) { + if (e.data && !e.isComposing) + field.value = ''; + }, false); // Whenever focus is gained, automatically click to ensure cursor is // actually placed within the field (the field may simply be highlighted or