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.
This commit is contained in:
Homa Wong 2014-04-21 10:37:06 -07:00
commit 163a6a9243
3 changed files with 27 additions and 8 deletions

View file

@ -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));

View file

@ -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;
}
};
});

View file

@ -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
}
});
});