Skip to content
Snippets Groups Projects
Commit ad2fccb4 authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

[anyword-hint addon] Optimize

Issue #2109
parent 58113e8a
No related branches found
No related tags found
No related merge requests found
......@@ -13,22 +13,20 @@
var curWord = start != end && curLine.slice(start, end);
var list = [], seen = {};
function scan(dir) {
var re = new RegExp(word.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
var line = cur.line, end = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
for (; line != end; line += dir) {
var text = editor.getLine(line), m;
var re = new RegExp(word.source, "g");
while (m = re.exec(text)) {
if (line == cur.line && m[0] === curWord) continue;
if ((!curWord || m[0].indexOf(curWord) == 0) && !seen.hasOwnProperty(m[0])) {
if ((!curWord || m[0].indexOf(curWord) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[0])) {
seen[m[0]] = true;
list.push(m[0]);
}
}
}
}
scan(-1);
scan(1);
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
});
})();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment