From c2805e03c84b6e598556fd06d1ede7aaeea7ce9c Mon Sep 17 00:00:00 2001
From: Valerio Virgillito
Date: Tue, 6 Mar 2012 16:17:54 -0800
Subject: Squashed commit FileIO-Build-Candidate into Master

Fixing issues with HTML and CSS URLs. Adjusted RegEx logic. Also code a mirror update and undo/redo changes were merged into this request.

Signed-off-by: Valerio Virgillito <valerio@motorola.com>
---
 imports/codemirror/lib/util/javascript-hint.js | 67 ++++++++++++++++++++++----
 1 file changed, 58 insertions(+), 9 deletions(-)
 mode change 100755 => 100644 imports/codemirror/lib/util/javascript-hint.js

(limited to 'imports/codemirror/lib/util/javascript-hint.js')

diff --git a/imports/codemirror/lib/util/javascript-hint.js b/imports/codemirror/lib/util/javascript-hint.js
old mode 100755
new mode 100644
index 4e88a7e4..2b904a51
--- a/imports/codemirror/lib/util/javascript-hint.js
+++ b/imports/codemirror/lib/util/javascript-hint.js
@@ -15,37 +15,81 @@
     }
     return arr.indexOf(item) != -1;
   }
-  
-  CodeMirror.javascriptHint = function(editor) {
+
+  function scriptHint(editor, keywords, getToken) {
     // Find the token at the cursor
-    var cur = editor.getCursor(), token = editor.getTokenAt(cur), tprop = token;
+    var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token;
     // If it's not a 'word-style' token, ignore the token.
-    if (!/^[\w$_]*$/.test(token.string)) {
+		if (!/^[\w$_]*$/.test(token.string)) {
       token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
                        className: token.string == "." ? "property" : null};
     }
     // If it is a property, find out what it is a property of.
     while (tprop.className == "property") {
-      tprop = editor.getTokenAt({line: cur.line, ch: tprop.start});
+      tprop = getToken(editor, {line: cur.line, ch: tprop.start});
       if (tprop.string != ".") return;
-      tprop = editor.getTokenAt({line: cur.line, ch: tprop.start});
+      tprop = getToken(editor, {line: cur.line, ch: tprop.start});
+      if (tprop.string == ')') {
+        var level = 1;
+        do {
+          tprop = getToken(editor, {line: cur.line, ch: tprop.start});
+          switch (tprop.string) {
+          case ')': level++; break;
+          case '(': level--; break;
+          default: break;
+          }
+        } while (level > 0)
+        tprop = getToken(editor, {line: cur.line, ch: tprop.start});
+				if (tprop.className == 'variable')
+					tprop.className = 'function';
+				else return; // no clue
+      }
       if (!context) var context = [];
       context.push(tprop);
     }
-    return {list: getCompletions(token, context),
+    return {list: getCompletions(token, context, keywords),
             from: {line: cur.line, ch: token.start},
             to: {line: cur.line, ch: token.end}};
   }
 
+  CodeMirror.javascriptHint = function(editor) {
+    return scriptHint(editor, javascriptKeywords,
+                      function (e, cur) {return e.getTokenAt(cur);});
+  }
+
+  function getCoffeeScriptToken(editor, cur) {
+  // This getToken, it is for coffeescript, imitates the behavior of
+  // getTokenAt method in javascript.js, that is, returning "property"
+  // type and treat "." as indepenent token.
+    var token = editor.getTokenAt(cur);
+    if (cur.ch == token.start + 1 && token.string.charAt(0) == '.') {
+      token.end = token.start;
+      token.string = '.';
+      token.className = "property";
+    }
+    else if (/^\.[\w$_]*$/.test(token.string)) {
+      token.className = "property";
+      token.start++;
+      token.string = token.string.replace(/\./, '');
+    }
+    return token;
+  }
+
+  CodeMirror.coffeescriptHint = function(editor) {
+    return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken);
+  }
+
   var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
                      "toUpperCase toLowerCase split concat match replace search").split(" ");
   var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " +
                     "lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
   var funcProps = "prototype apply call bind".split(" ");
-  var keywords = ("break case catch continue debugger default delete do else false finally for function " +
+  var javascriptKeywords = ("break case catch continue debugger default delete do else false finally for function " +
                   "if in instanceof new null return switch throw true try typeof var void while with").split(" ");
+  var coffeescriptKeywords = ("and break catch class continue delete do else extends false finally for " +
+                  "if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" ");
 
-  function getCompletions(token, context) {
+  function getCompletions(token, context, keywords) {
     var found = [], start = token.string;
     function maybeAdd(str) {
       if (str.indexOf(start) == 0 && !arrayContains(found, str)) found.push(str);
@@ -67,6 +111,11 @@
         base = "";
       else if (obj.className == "atom")
         base = 1;
+      else if (obj.className == "function") {
+        if (window.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') &&
+            (typeof jQuery == 'function')) base = jQuery();
+        else if (window._ != null && (obj.string == '_') && (typeof _ == 'function')) base = _();
+      }
       while (base != null && context.length)
         base = base[context.pop().string];
       if (base != null) gatherCompletions(base);
-- 
cgit v1.2.3