mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-08 06:01:22 +00:00
Assume text inserted in eventTarget at end (cannot rely on selectionStart or selectionEnd). Reset eventTarget value when focus gained.
This commit is contained in:
@@ -508,35 +508,33 @@ GuacamoleUI.attach = function(guac) {
|
|||||||
// Monitor whether the event target is focused
|
// Monitor whether the event target is focused
|
||||||
var eventTargetFocused = false;
|
var eventTargetFocused = false;
|
||||||
|
|
||||||
|
// Save length for calculation of changed value
|
||||||
|
var currentLength = GuacamoleUI.eventTarget.value.length;
|
||||||
|
|
||||||
GuacamoleUI.eventTarget.onfocus = function() {
|
GuacamoleUI.eventTarget.onfocus = function() {
|
||||||
eventTargetFocused = true;
|
eventTargetFocused = true;
|
||||||
|
GuacamoleUI.eventTarget.value = "";
|
||||||
|
currentLength = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
GuacamoleUI.eventTarget.onblur = function() {
|
GuacamoleUI.eventTarget.onblur = function() {
|
||||||
eventTargetFocused = false;
|
eventTargetFocused = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save length for calculation of changed value
|
|
||||||
var currentLength = GuacamoleUI.eventTarget.value.length;
|
|
||||||
|
|
||||||
// If text is input directly into event target without typing (as with
|
// If text is input directly into event target without typing (as with
|
||||||
// voice input, for example), type automatically.
|
// voice input, for example), type automatically.
|
||||||
GuacamoleUI.eventTarget.oninput = function(e) {
|
GuacamoleUI.eventTarget.oninput = function(e) {
|
||||||
|
|
||||||
// Calculate current length and change in length
|
// Calculate current length and change in length
|
||||||
var newLength = GuacamoleUI.eventTarget.value.length;
|
var oldLength = currentLength;
|
||||||
var changeLength = newLength - currentLength;
|
currentLength = GuacamoleUI.eventTarget.value.length;
|
||||||
currentLength = newLength;
|
|
||||||
|
|
||||||
// If deleted or replaced text, ignore
|
// If deleted or replaced text, ignore
|
||||||
if (changeLength <= 0)
|
if (currentLength <= oldLength)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Get changed text
|
// Get changed text
|
||||||
var text = GuacamoleUI.eventTarget.value.substring(
|
var text = GuacamoleUI.eventTarget.value.substring(oldLength);
|
||||||
GuacamoleUI.eventTarget.selectionStart,
|
|
||||||
GuacamoleUI.eventTarget.selectionStart + changeLength
|
|
||||||
);
|
|
||||||
|
|
||||||
// Send each character
|
// Send each character
|
||||||
for (var i=0; i<text.length; i++) {
|
for (var i=0; i<text.length; i++) {
|
||||||
|
Reference in New Issue
Block a user