]> matita.cs.unibo.it Git - helm.git/commitdiff
more tests on keyboard events.
authorWilmer Ricciotti <ricciott@cs.unibo.it>
Wed, 13 Jul 2011 15:28:54 +0000 (15:28 +0000)
committerWilmer Ricciotti <ricciott@cs.unibo.it>
Wed, 13 Jul 2011 15:28:54 +0000 (15:28 +0000)
matitaB/matita/matitaweb.js

index 4b99a23a286a471ca341f67c8fd4f4da25f3d8be..4c4d0a406568bb62ebf1be8f7e710bf7b7fc613f 100644 (file)
@@ -107,6 +107,29 @@ function suppressdefault(e,flag)
    }
    return !flag;
 }
+
+function restoreSelection() {
+    unlocked.focus();
+    if (savedRange != null) {
+        if (window.getSelection)//non IE and there is already a selection
+        {
+            var s = window.getSelection();
+            if (s.rangeCount > 0) 
+                s.removeAllRanges();
+            s.addRange(savedRange);
+        }
+        else 
+            if (document.createRange)//non IE and no selection
+            {
+                window.getSelection().addRange(savedRange);
+            }
+            else 
+                if (document.selection)//IE
+                {
+                    savedRange.select();
+                }
+    }
+}
  
 function keypress(e)
 {
@@ -122,29 +145,10 @@ function keypress(e)
          post = unlocked.innerHTML.substring(j);
          if (match == '\\to') {
              unlocked.innerHTML = pre + "-> " + post;
-            unlocked.focus();
-             if (savedRange != null) {
-                 if (window.getSelection)//non IE and there is already a selection
-                 {
-                     var s = window.getSelection();
-                     if (s.rangeCount > 0) 
-                         s.removeAllRanges();
-                     s.addRange(savedRange);
-                 }
-                 else 
-                     if (document.createRange)//non IE and no selection
-                     {
-                         window.getSelection().addRange(savedRange);
-                     }
-                     else 
-                         if (document.selection)//IE
-                         {
-                             savedRange.select();
-                         }
-             }
-
+             restoreSelection(); 
             return suppressdefault(e,true);
          }
+          restoreSelection(); 
          else return suppressdefault(e,false);
        }
        else return suppressdefault(e,false);