fix #1973 custom array of autocompleters never used
This commit is contained in:
parent
7e2dda1e18
commit
d0acc15e67
1 changed files with 23 additions and 16 deletions
|
|
@ -120,40 +120,45 @@ var loadSnippetFile = function(id) {
|
|||
});
|
||||
};
|
||||
|
||||
var doLiveAutocomplete = function(e) {
|
||||
var editor = e.editor;
|
||||
var text = e.args || "";
|
||||
function getCompletionPrefix(editor) {
|
||||
var pos = editor.getCursorPosition();
|
||||
var line = editor.session.getLine(pos.row);
|
||||
var hasCompleter = editor.completer && editor.completer.activated;
|
||||
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
|
||||
|
||||
//Try to find custom prefixes on the completers
|
||||
completers.forEach(function(completer) {
|
||||
// Try to find custom prefixes on the completers
|
||||
editor.completers.forEach(function(completer) {
|
||||
if (completer.identifierRegexps) {
|
||||
completer.identifierRegexps.forEach(function(identifierRegex) {
|
||||
if (!prefix) {
|
||||
if (!prefix && identifierRegex)
|
||||
prefix = util.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return prefix;
|
||||
}
|
||||
|
||||
var doLiveAutocomplete = function(e) {
|
||||
var editor = e.editor;
|
||||
var text = e.args || "";
|
||||
var hasCompleter = editor.completer && editor.completer.activated;
|
||||
|
||||
|
||||
|
||||
// We don't want to autocomplete with no prefix
|
||||
if (e.command.name === "backspace" && !prefix) {
|
||||
if (hasCompleter)
|
||||
if (e.command.name === "backspace") {
|
||||
if (hasCompleter && !getCompletionPrefix(editor))
|
||||
editor.completer.detach();
|
||||
}
|
||||
else if (e.command.name === "insertstring") {
|
||||
var prefix = getCompletionPrefix(editor);
|
||||
// Only autocomplete if there's a prefix that can be matched
|
||||
if (prefix && !hasCompleter) {
|
||||
if (!editor.completer) {
|
||||
// Create new autocompleter
|
||||
editor.completer = new Autocomplete();
|
||||
// Disable autoInsert
|
||||
editor.completer.autoSelect = false;
|
||||
editor.completer.autoInsert = false;
|
||||
}
|
||||
// Disable autoInsert
|
||||
editor.completer.autoSelect = false;
|
||||
editor.completer.autoInsert = false;
|
||||
editor.completer.showPopup(editor);
|
||||
} else if (!prefix && hasCompleter) {
|
||||
// When the prefix is empty
|
||||
|
|
@ -168,7 +173,8 @@ require("../config").defineOptions(Editor.prototype, "editor", {
|
|||
enableBasicAutocompletion: {
|
||||
set: function(val) {
|
||||
if (val) {
|
||||
this.completers = Array.isArray(val)? val: completers;
|
||||
if (!this.completers)
|
||||
this.completers = Array.isArray(val)? val: completers;
|
||||
this.commands.addCommand(Autocomplete.startCommand);
|
||||
} else {
|
||||
this.commands.removeCommand(Autocomplete.startCommand);
|
||||
|
|
@ -183,7 +189,8 @@ require("../config").defineOptions(Editor.prototype, "editor", {
|
|||
enableLiveAutocompletion: {
|
||||
set: function(val) {
|
||||
if (val) {
|
||||
this.completers = Array.isArray(val)? val: completers;
|
||||
if (!this.completers)
|
||||
this.completers = Array.isArray(val)? val: completers;
|
||||
// On each change automatically trigger the autocomplete
|
||||
this.commands.on('afterExec', doLiveAutocomplete);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue