Assume text inserted in eventTarget at end (cannot rely on selectionStart or selectio...
authorMichael Jumper <zhangmaike@users.sourceforge.net>
Sat, 31 Mar 2012 05:10:20 +0000 (22:10 -0700)
committerMichael Jumper <zhangmaike@users.sourceforge.net>
Sat, 31 Mar 2012 05:10:20 +0000 (22:10 -0700)
src/main/webapp/scripts/interface.js

index 05aa3a9..9002e7e 100644 (file)
@@ -508,35 +508,33 @@ GuacamoleUI.attach = function(guac) {
     // Monitor whether the event target is focused
     var eventTargetFocused = false;
 
     // Monitor whether the event target is focused
     var eventTargetFocused = false;
 
+    // Save length for calculation of changed value
+    var currentLength = GuacamoleUI.eventTarget.value.length;
+
     GuacamoleUI.eventTarget.onfocus = function() {
         eventTargetFocused = true;
     GuacamoleUI.eventTarget.onfocus = function() {
         eventTargetFocused = true;
+        GuacamoleUI.eventTarget.value = "";
+        currentLength = 0;
     };
 
     GuacamoleUI.eventTarget.onblur = function() {
         eventTargetFocused = false;
     };
 
     };
 
     GuacamoleUI.eventTarget.onblur = function() {
         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
     // voice input, for example), type automatically.
     GuacamoleUI.eventTarget.oninput = function(e) {
 
         // Calculate current length and change in length
     // If text is input directly into event target without typing (as with
     // voice input, for example), type automatically.
     GuacamoleUI.eventTarget.oninput = function(e) {
 
         // Calculate current length and change in length
-        var newLength = GuacamoleUI.eventTarget.value.length;
-        var changeLength = newLength - currentLength;
-        currentLength = newLength;
+        var oldLength = currentLength;
+        currentLength = GuacamoleUI.eventTarget.value.length;
         
         // If deleted or replaced text, ignore
         
         // If deleted or replaced text, ignore
-        if (changeLength <= 0)
+        if (currentLength <= oldLength)
             return;
 
         // Get changed text
             return;
 
         // Get changed text
-        var text = GuacamoleUI.eventTarget.value.substring(
-            GuacamoleUI.eventTarget.selectionStart,
-            GuacamoleUI.eventTarget.selectionStart + changeLength
-        );
+        var text = GuacamoleUI.eventTarget.value.substring(oldLength);
 
         // Send each character
         for (var i=0; i<text.length; i++) {
 
         // Send each character
         for (var i=0; i<text.length; i++) {