From 9391e0b9bb2a4f9d4978ff83ed02b3a35e3248a7 Mon Sep 17 00:00:00 2001 From: Homa Wong Date: Sun, 20 Apr 2014 15:14:09 -0700 Subject: [PATCH 1/4] Fix live auto completion. Didn't set completers when enabling it. --- lib/ace/ext/language_tools.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ace/ext/language_tools.js b/lib/ace/ext/language_tools.js index 1933b4ff..83cfe2be 100644 --- a/lib/ace/ext/language_tools.js +++ b/lib/ace/ext/language_tools.js @@ -175,6 +175,7 @@ require("../config").defineOptions(Editor.prototype, "editor", { set: function(val) { if (val) { // On each change automatically trigger the autocomplete + this.completers = completers; this.commands.on('afterExec', doLiveAutocomplete); } else { this.commands.removeListener('afterExec', doLiveAutocomplete); From 163a6a92430f6ee13dc94c1817fdeee7d4578b69 Mon Sep 17 00:00:00 2001 From: Homa Wong Date: Mon, 21 Apr 2014 10:37:06 -0700 Subject: [PATCH 2/4] Update text_completer and util to support unicode characters autocomplete. Update language_tools to support pass in completers at enableLiveAutocomplete and enableBasicAutocomplete so user can further customize the completion behavior. --- lib/ace/autocomplete/text_completer.js | 2 +- lib/ace/autocomplete/util.js | 8 ++++---- lib/ace/ext/language_tools.js | 25 ++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/ace/autocomplete/text_completer.js b/lib/ace/autocomplete/text_completer.js index 723ff69a..6eebfc61 100644 --- a/lib/ace/autocomplete/text_completer.js +++ b/lib/ace/autocomplete/text_completer.js @@ -31,7 +31,7 @@ define(function(require, exports, module) { var Range = require("../range").Range; - var splitRegex = /[^a-zA-Z_0-9\$\-]+/; + var splitRegex = /[^a-zA-Z_0-9\$\-\u00C0-\u1FFF\u2C00-\uD7FF\w]+/; function getWordIndex(doc, pos) { var textBefore = doc.getTextRange(Range.fromPoints({row: 0, column:0}, pos)); diff --git a/lib/ace/autocomplete/util.js b/lib/ace/autocomplete/util.js index 8b7c1151..994219ff 100644 --- a/lib/ace/autocomplete/util.js +++ b/lib/ace/autocomplete/util.js @@ -43,9 +43,9 @@ exports.parForEach = function(array, fn, callback) { callback(result, err); }); } -} +}; -var ID_REGEX = /[a-zA-Z_0-9\$-]/; +var ID_REGEX = /[a-zA-Z_0-9\$-]|[^\u0000-\u007F]/; exports.retrievePrecedingIdentifier = function(text, pos, regex) { regex = regex || ID_REGEX; @@ -57,7 +57,7 @@ exports.retrievePrecedingIdentifier = function(text, pos, regex) { break; } return buf.reverse().join(""); -} +}; exports.retrieveFollowingIdentifier = function(text, pos, regex) { regex = regex || ID_REGEX; @@ -69,6 +69,6 @@ exports.retrieveFollowingIdentifier = function(text, pos, regex) { break; } return buf; -} +}; }); diff --git a/lib/ace/ext/language_tools.js b/lib/ace/ext/language_tools.js index 83cfe2be..1b46635e 100644 --- a/lib/ace/ext/language_tools.js +++ b/lib/ace/ext/language_tools.js @@ -72,6 +72,11 @@ exports.addCompleter = function(completer) { completers.push(completer); }; +// Exports existing completer so that user can construct his own set of completers. +exports.textCompleter = textCompleter; +exports.keyWordCompleter = keyWordCompleter; +exports.snippetCompleter = snippetCompleter; + var expandSnippet = { name: "expandSnippet", exec: function(editor) { @@ -126,7 +131,7 @@ var doLiveAutocomplete = function(e) { //Try to find custom prefixes on the completers completers.forEach(function(completer) { if (completer.identifierRegexps) { - completer.identifierRegexps.forEach(function(identifierRegex){ + completer.identifierRegexps.forEach(function(identifierRegex) { if (!prefix) { prefix = util.retrievePrecedingIdentifier(line, pos.column, identifierRegex); } @@ -136,7 +141,7 @@ var doLiveAutocomplete = function(e) { // We don't want to autocomplete with no prefix if (e.command.name === "backspace" && !prefix) { - if (hasCompleter) + if (hasCompleter) editor.completer.detach(); } else if (e.command.name === "insertstring") { @@ -163,6 +168,10 @@ require("../config").defineOptions(Editor.prototype, "editor", { enableBasicAutocompletion: { set: function(val) { if (val) { + if (Array.isArray(val)) { + completers = val; + } + this.completers = completers; this.commands.addCommand(Autocomplete.startCommand); } else { @@ -171,9 +180,20 @@ require("../config").defineOptions(Editor.prototype, "editor", { }, value: false }, + /** + * Enable live autocomplete. If the value is an array, it is assumed to be an array of completer + * and will use them instead of the default completers. + * NOTE: Should this be renamed to enableLiveAutocompletion to match enableBasicAutocompletion? + */ enableLiveAutocomplete: { set: function(val) { if (val) { + if (Array.isArray(val)) { + completers = val; + } + + this.completers = completers; + // On each change automatically trigger the autocomplete this.completers = completers; this.commands.on('afterExec', doLiveAutocomplete); @@ -197,5 +217,4 @@ require("../config").defineOptions(Editor.prototype, "editor", { value: false } }); - }); From 54a1060a81d175df15af86e5236abdfffd0f9ab2 Mon Sep 17 00:00:00 2001 From: Homa Wong Date: Thu, 24 Apr 2014 00:38:40 -0700 Subject: [PATCH 3/4] Rename enableLiveAutocomplete to enableLiveAutocompletion to match enableBasicAutocompletion --- lib/ace/ext/language_tools.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ace/ext/language_tools.js b/lib/ace/ext/language_tools.js index 1b46635e..f7c16d66 100644 --- a/lib/ace/ext/language_tools.js +++ b/lib/ace/ext/language_tools.js @@ -185,7 +185,7 @@ require("../config").defineOptions(Editor.prototype, "editor", { * and will use them instead of the default completers. * NOTE: Should this be renamed to enableLiveAutocompletion to match enableBasicAutocompletion? */ - enableLiveAutocomplete: { + enableLiveAutocompletion: { set: function(val) { if (val) { if (Array.isArray(val)) { From 801875605161874d61cd244f926754b16a0ccc0d Mon Sep 17 00:00:00 2001 From: Homa Wong Date: Sun, 4 May 2014 09:45:12 -0700 Subject: [PATCH 4/4] Update regex and condition check according to suggestion --- lib/ace/autocomplete/util.js | 2 +- lib/ace/ext/language_tools.js | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/ace/autocomplete/util.js b/lib/ace/autocomplete/util.js index 994219ff..341a6b92 100644 --- a/lib/ace/autocomplete/util.js +++ b/lib/ace/autocomplete/util.js @@ -45,7 +45,7 @@ exports.parForEach = function(array, fn, callback) { } }; -var ID_REGEX = /[a-zA-Z_0-9\$-]|[^\u0000-\u007F]/; +var ID_REGEX = /[a-zA-Z_0-9\$-\u007F-\uFFFF]/; exports.retrievePrecedingIdentifier = function(text, pos, regex) { regex = regex || ID_REGEX; diff --git a/lib/ace/ext/language_tools.js b/lib/ace/ext/language_tools.js index f7c16d66..7abc2ef8 100644 --- a/lib/ace/ext/language_tools.js +++ b/lib/ace/ext/language_tools.js @@ -168,11 +168,7 @@ require("../config").defineOptions(Editor.prototype, "editor", { enableBasicAutocompletion: { set: function(val) { if (val) { - if (Array.isArray(val)) { - completers = val; - } - - this.completers = completers; + this.completers = Array.isArray(val)? val: completers; this.commands.addCommand(Autocomplete.startCommand); } else { this.commands.removeCommand(Autocomplete.startCommand); @@ -188,11 +184,7 @@ require("../config").defineOptions(Editor.prototype, "editor", { enableLiveAutocompletion: { set: function(val) { if (val) { - if (Array.isArray(val)) { - completers = val; - } - - this.completers = completers; + this.completers = Array.isArray(val)? val: completers; // On each change automatically trigger the autocomplete this.completers = completers;