5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
var WORD = /[\w$]+/, RANGE = 500;
16
CodeMirror.registerHelper("hint", "anyword", function(editor, options) {
17
var word = options && options.word || WORD;
18
var range = options && options.range || RANGE;
19
var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
20
var end = cur.ch, start = end;
21
while (start && word.test(curLine.charAt(start - 1))) --start;
22
var curWord = start != end && curLine.slice(start, end);
24
var list = options && options.list || [], seen = {};
25
var re = new RegExp(word.source, "g");
26
for (var dir = -1; dir <= 1; dir += 2) {
27
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
28
for (; line != endLine; line += dir) {
29
var text = editor.getLine(line), m;
30
while (m = re.exec(text)) {
31
if (line == cur.line && m[0] === curWord) continue;
32
if ((!curWord || m[0].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[0])) {
39
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};