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