Merge pull request #1924 from unional/liveAutocomplete

Improve auto complete
This commit is contained in:
Harutyun Amirjanyan 2014-05-05 17:40:47 +02:00
commit 6779345049
3 changed files with 22 additions and 10 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\$-\u007F-\uFFFF]/;
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,7 +168,7 @@ require("../config").defineOptions(Editor.prototype, "editor", {
enableBasicAutocompletion: {
set: function(val) {
if (val) {
this.completers = completers;
this.completers = Array.isArray(val)? val: completers;
this.commands.addCommand(Autocomplete.startCommand);
} else {
this.commands.removeCommand(Autocomplete.startCommand);
@ -171,10 +176,18 @@ require("../config").defineOptions(Editor.prototype, "editor", {
},
value: false
},
enableLiveAutocomplete: {
/**
* 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?
*/
enableLiveAutocompletion: {
set: function(val) {
if (val) {
this.completers = Array.isArray(val)? val: completers;
// On each change automatically trigger the autocomplete
this.completers = completers;
this.commands.on('afterExec', doLiveAutocomplete);
} else {
this.commands.removeListener('afterExec', doLiveAutocomplete);
@ -196,5 +209,4 @@ require("../config").defineOptions(Editor.prototype, "editor", {
value: false
}
});
});