fixing @ autocomplete swallowing cursor, selection keys
authorNicholas Bollweg (Nick) <nick.bollweg@gmail.com>
Sun, 03 Nov 2013 08:48:08 -0500
changeset 2084 0a3d183d5236
parent 2083 4c4a8f67348d
child 2085 d33c7240318c
fixing @ autocomplete swallowing cursor, selection keys
playground/playground.js
--- a/playground/playground.js	Sat Nov 02 10:35:09 2013 -0400
+++ b/playground/playground.js	Sun Nov 03 08:48:08 2013 -0500
@@ -195,6 +195,16 @@
       });
     };
     
+    // these are the keys that move the cursor
+    var noHint = [
+      8, // backspace
+      9, // hey! where's my tab?
+      33, 34, 35, 46, // pg/home/end
+      37, 38, 39, 40, // arrows
+      12, // enter
+      27 //escape
+    ];
+    
     $.each(playground.editors, function(key){
       var editor = playground.editors[key] = CodeMirror.fromTextArea(
         $("#" + key)[0], {
@@ -207,7 +217,8 @@
           theme: "elegant",
           lint: true,
           extraKeys: {
-            "Ctrl-Space": "autocomplete"
+            "Ctrl-Space": "autocomplete",
+            "U+0040": "at_autocomplete"
           },
           _playground_key: key
         });
@@ -220,6 +231,7 @@
       
       // check on every keyup for `@`: doesn't get caught by (extra|custom)Keys
       editor.on("keyup", function(editor, evt){
+        if(noHint.indexOf(evt.keyCode) >= 0){ return; }
         var cursor = editor.getCursor(),
           token = editor.getTokenAt(cursor),
           chr = token.string[cursor.ch - token.start - 1];