Skip to content

Commit

Permalink
Define and use an arrayContains function rather than directly using a…
Browse files Browse the repository at this point in the history
…rray.indexOf, this fixes the auto completion demo in IE6/7/8.
  • Loading branch information
Page authored and marijnh committed Nov 9, 2011
1 parent be73183 commit c4aff2b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/util/javascript-hint.js
Expand Up @@ -2,7 +2,20 @@
function forEach(arr, f) {
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
}


function arrayContains(arr, item) {
if (!Array.prototype.indexOf) {
var i = arr.length;
while (i--) {
if (arr[i] === item) {
return true;
}
}
return false;
}
return arr.indexOf(item) != -1;
}

CodeMirror.javascriptHint = function(editor) {
// Find the token at the cursor
var cur = editor.getCursor(), token = editor.getTokenAt(cur), tprop = token;
Expand Down Expand Up @@ -35,7 +48,7 @@
function getCompletions(token, context) {
var found = [], start = token.string;
function maybeAdd(str) {
if (str.indexOf(start) == 0 && found.indexOf(str) == -1) found.push(str);
if (str.indexOf(start) == 0 && !arrayContains(found, str)) found.push(str);
}
function gatherCompletions(obj) {
if (typeof obj == "string") forEach(stringProps, maybeAdd);
Expand Down

0 comments on commit c4aff2b

Please sign in to comment.