From 356a54c76205ca04344e43ebe9a663771d413c2c Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 22 Aug 2014 12:29:54 +0800 Subject: [PATCH] . --- static/js/editor.js | 49 ++++++-------------------------------------- templates/index.html | 1 + 2 files changed, 7 insertions(+), 43 deletions(-) diff --git a/static/js/editor.js b/static/js/editor.js index aa10a48..2063df3 100644 --- a/static/js/editor.js +++ b/static/js/editor.js @@ -15,8 +15,6 @@ var editors = { while (start && word.test(curLine.charAt(start - 1))) --start; var curWord = start != end && curLine.slice(start, end); - console.log(curWord) - var request = { code: editor.getValue(), cursorLine: editor.getCursor().line, @@ -48,50 +46,11 @@ var editors = { return {list: autocompleteHints, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)}; }); - - CodeMirror.registerHelper("hint", "anyword", function(editor, options) { - var WORD = /[\w$]+/, RANGE = 500; - - var word = options && options.word || WORD; - var range = options && options.range || RANGE; - var cur = editor.getCursor(), curLine = editor.getLine(cur.line); - var start = cur.ch, end = start; - while (end < curLine.length && word.test(curLine.charAt(end))) ++end; - while (start && word.test(curLine.charAt(start - 1))) --start; - var curWord = start != end && curLine.slice(start, end); - - var list = [], seen = {}; - var re = new RegExp(word.source, "g"); - for (var dir = -1; dir <= 1; dir += 2) { - var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir; - for (; line != endLine; line += dir) { - var text = editor.getLine(line), m; - while (m = re.exec(text)) { - if (line == cur.line && m[0] === curWord) continue; - if ((!curWord || m[0].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[0])) { - seen[m[0]] = true; - list.push(m[0]); - } - } - } - } - - console.log(list); - - return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)}; - }); - - CodeMirror.commands.anyword = function(cm) { - cm.showHint({hint: CodeMirror.hint.anyword, completeSingle: false}); - }; - CodeMirror.commands.autocompleteAfterDot = function(cm) { var cur = cm.getCursor(); console.log(cm.getRange(CodeMirror.Pos(cur.line, cur.ch - 1), cur)); - var tok = cm.getTokenAt(cm.getCursor()); - console.log(tok) - + // var token = cm.getTokenAt(cm.getCursor()); setTimeout(function() { if (!cm.state.completionActive) { @@ -101,6 +60,10 @@ var editors = { return CodeMirror.Pass; }; + + CodeMirror.commands.autocompleteAnyWord = function(cm) { + cm.showHint({hint: CodeMirror.hint.auto}); + } }, _initTabs: function() { var $tabsPanel = $(".edit-panel .tabs-panel"), @@ -172,7 +135,7 @@ var editors = { theme: 'lesser-dark', indentUnit: 4, extraKeys: { - "Ctrl-\\": "anyword", + "Ctrl-\\": "autocompleteAnyWord", ".": "autocompleteAfterDot" } }); diff --git a/templates/index.html b/templates/index.html index d08e84f..bace3d9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -69,6 +69,7 @@ +