LaravelTest
41 строка · 1.6 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14var WORD = /[\w$]+/, RANGE = 500;15
16CodeMirror.registerHelper("hint", "anyword", function(editor, options) {17var word = options && options.word || WORD;18var range = options && options.range || RANGE;19var cur = editor.getCursor(), curLine = editor.getLine(cur.line);20var end = cur.ch, start = end;21while (start && word.test(curLine.charAt(start - 1))) --start;22var curWord = start != end && curLine.slice(start, end);23
24var list = options && options.list || [], seen = {};25var re = new RegExp(word.source, "g");26for (var dir = -1; dir <= 1; dir += 2) {27var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;28for (; line != endLine; line += dir) {29var text = editor.getLine(line), m;30while (m = re.exec(text)) {31if (line == cur.line && m[0] === curWord) continue;32if ((!curWord || m[0].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[0])) {33seen[m[0]] = true;34list.push(m[0]);35}36}37}38}39return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};40});41});42