##// END OF EJS Templates
fix and retab javascript
Matthias BUSSONNIER -
Show More
@@ -1,90 +1,72
1 // highly adapted for codemiror jshint
1 // highly adapted for codemiror jshint
2
2
3 (function () {
3 (function () {
4 "use strict";
4 "use strict";
5 function forEach(arr, f) {
5 function forEach(arr, f) {
6 for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
6 for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
7 }
8
9 function arrayContains(arr, item) {
10 if (!Array.prototype.indexOf) {
11 var i = arr.length;
12 while (i--) {
13 if (arr[i] === item) {
14 return true;
15 }
16 }
17 return false;
18 }
7 }
19 return arr.indexOf(item) != -1;
8
20 }
9 function arrayContains(arr, item) {
21
10 if (!Array.prototype.indexOf) {
22 CodeMirror.contextHint = function(editor) {
11 var i = arr.length;
23 // Find the token at the cursor
12 while (i--) {
24 var cur = editor.getCursor(), token = editor.getTokenAt(cur), tprop = token;
13 if (arr[i] === item) {return true;}
25 // If it's not a 'word-style' token, ignore the token.
14 }
26 // If it is a property, find out what it is a property of.
15 return false;
27
16 }
28 var list = new Array();
17 return arr.indexOf(item) != -1;
29 var clist = getCompletions(token,editor) ;
30 for( var i = 0 ; i < clist.length ; i++)
31 {
32 list.push(
33 {
34 str : clist[i],
35 type : "context",
36 from : {line: cur.line, ch: token.start},
37 to : {line: cur.line, ch: token.end}
38 }
39 )
40
41 }
18 }
42 return list;
19
43 }
20 CodeMirror.contextHint = function(editor) {
44
21 // Find the token at the cursor
45 // find all 'words' of current cell
22 var cur = editor.getCursor(), token = editor.getTokenAt(cur), tprop = token;
46 function getAllTokens(editor)
23 // If it's not a 'word-style' token, ignore the token.
47 {
24 // If it is a property, find out what it is a property of.
48 var found = [];
25 var list = new Array();
49 // get all text remove and split it before dot and at space
26 var clist = getCompletions(token,editor);
50 // keep the dot for completing token that also start with dot
27 for(var i = 0 ; i < clist.length ; i++)
51 var candidates = editor.getValue()
28 {
52 .replace(/[. ]/g,"\n")
29 list.push(
53 .split('\n');
30 { str : clist[i],
54 // append to arry if not already (the function)
31 type : "context",
55 function maybeAdd(str) {
32 from : {line: cur.line, ch: token.start},
56 if (!arrayContains(found, str)) found.push(str);
33 to : {line: cur.line, ch: token.end} })
34 }
35 return list;
57 }
36 }
58
37
59 // append to arry if not already
38 // find all 'words' of current cell
60 // (here we do it )
39 function getAllTokens(editor)
61 for( var c in candidates )
62 {
40 {
63 if(candidates[c].length >= 1){
41 var found = [];
64 maybeAdd(candidates[c]);}
42 // get all text remove and split it before dot and at space
43 // keep the dot for completing token that also start with dot
44 var candidates = editor.getValue()
45 .replace(/[.]/g," .")
46 .replace(/[ ]/g,"\n")
47 .split('\n');
48 // append to arry if not already (the function)
49 function maybeAdd(str) {
50 if (!arrayContains(found, str)) found.push(str);
51 }
52 // append to arry if not already
53 // (here we do it )
54 for( var c in candidates )
55 {
56 if(candidates[c].length >= 1){
57 maybeAdd(candidates[c]);}
58 }
59 return found;
65 }
60 }
66 return found;
67
61
68 }
62 function getCompletions(token,editor)
69
70 function getCompletions(token,editor)
71 {
72 var candidates = getAllTokens(editor);
73 // filter all token that have a common start (but nox exactly) the lenght of the current token
74 var prependchar ='';
75 if(token.string.indexOf('.') == 0)
76 {
77 prependchar = '.'
78 }
79 var lambda = function(x){
80 x = prependchar+x;
81 return (x.indexOf(token.string)==0 && x != token.string)};
82 var filterd = candidates.filter(lambda);
83 for( var i in filterd)
84 {
63 {
85 // take care of reappending '.' at the beginning
64 var candidates = getAllTokens(editor);
86 filterd[i] = prependchar+filterd[i];
65 // filter all token that have a common start (but nox exactly) the lenght of the current token
66 var lambda = function(x){
67 return (x.indexOf(token.string)==0 && x != token.string)
68 };
69 var filterd = candidates.filter(lambda);
70 return filterd;
87 }
71 }
88 return filterd;
89 }
90 })();
72 })();
General Comments 0
You need to be logged in to leave comments. Login now