From 9f6b2fad37aa8f087d1464523c4ff1ee75ef861f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 18 Dec 2017 14:56:39 -0800 Subject: [PATCH] GUACAMOLE-352: Additionally click() while attempting to refocus the input sink field. Do not rely on autofocus, which may result in the field being partly focused (outlined as focused) but not receiving any actual text input. --- .../src/main/webapp/modules/Keyboard.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/webapp/modules/Keyboard.js b/guacamole-common-js/src/main/webapp/modules/Keyboard.js index 3a114db4c..b0930c2ca 100644 --- a/guacamole-common-js/src/main/webapp/modules/Keyboard.js +++ b/guacamole-common-js/src/main/webapp/modules/Keyboard.js @@ -1440,8 +1440,8 @@ Guacamole.Keyboard.InputSink = function InputSink() { * @type {Element} */ var field = document.createElement('textarea'); - field.setAttribute('autofocus', 'autofocus'); field.style.position = 'fixed'; + field.style.outline = 'none'; field.style.border = 'none'; field.style.width = '10px'; field.style.height = '10px'; @@ -1463,6 +1463,16 @@ Guacamole.Keyboard.InputSink = function InputSink() { // Keep internal field contents clear field.addEventListener("change", clear, false); + // Whenever focus is gained, automatically click to ensure cursor is + // actually placed within the field (the field may simply be highlighted or + // outlined otherwise) + field.addEventListener("focus", function focusReceived() { + window.setTimeout(function deferRefocus() { + field.click(); + field.select(); + }, 0); + }, true); + /** * Attempts to focus the underlying input field. The focus attempt occurs * asynchronously, and may silently fail depending on browser restrictions. @@ -1470,7 +1480,6 @@ Guacamole.Keyboard.InputSink = function InputSink() { this.focus = function focus() { window.setTimeout(function deferRefocus() { field.focus(); // Focus must be deferred to work reliably across browsers - field.select(); }, 0); };