doing token introspection to determine @ for autocomplete
authorNicholas Bollweg (Nick) <nick.bollweg@gmail.com>
Sat, 02 Nov 2013 10:35:09 -0400
changeset 2083 4c4a8f67348d
parent 2082 d8ce908a3350
child 2084 0a3d183d5236
doing token introspection to determine @ for autocomplete
playground/playground.js
--- a/playground/playground.js	Fri Nov 01 13:28:32 2013 -0400
+++ b/playground/playground.js	Sat Nov 02 10:35:09 2013 -0400
@@ -207,18 +207,26 @@
           theme: "elegant",
           lint: true,
           extraKeys: {
-            "Ctrl-Space": "autocomplete",
-            "Shift-2": "at_autocomplete"
+            "Ctrl-Space": "autocomplete"
           },
           _playground_key: key
         });
       
       // set up 'process' areas to process JSON-LD after typing
-      editor
-        .on("change", function() {
-          clearTimeout(processTimer);
-          processTimer = setTimeout(playground.process, 500);
-        });
+      editor.on("change", function() {
+        clearTimeout(processTimer);
+        processTimer = setTimeout(playground.process, 500);
+      });
+      
+      // check on every keyup for `@`: doesn't get caught by (extra|custom)Keys
+      editor.on("keyup", function(editor, evt){
+        var cursor = editor.getCursor(),
+          token = editor.getTokenAt(cursor),
+          chr = token.string[cursor.ch - token.start - 1];
+        if(chr === "@"){
+          CodeMirror.commands.at_autocomplete(editor, evt);
+        }
+      });
     }); // each
   };