Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
51007 views
1
(function() {
2
"use strict";
3
4
var WORD = /[\w$]+/, RANGE = 500;
5
6
CodeMirror.registerHelper("hint", "anyword", function(editor, options) {
7
var word = options && options.word || WORD;
8
var range = options && options.range || RANGE;
9
var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
10
var start = cur.ch, end = start;
11
while (end < curLine.length && word.test(curLine.charAt(end))) ++end;
12
while (start && word.test(curLine.charAt(start - 1))) --start;
13
var curWord = start != end && curLine.slice(start, end);
14
15
var list = [], seen = {};
16
var re = new RegExp(word.source, "g");
17
for (var dir = -1; dir <= 1; dir += 2) {
18
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
19
for (; line != endLine; line += dir) {
20
var text = editor.getLine(line), m;
21
while (m = re.exec(text)) {
22
if (line == cur.line && m[0] === curWord) continue;
23
if ((!curWord || m[0].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[0])) {
24
seen[m[0]] = true;
25
list.push(m[0]);
26
}
27
}
28
}
29
}
30
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
31
});
32
})();
33
34