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) {
|
function getCompletionPrefix(editor) {
|
||||||
var editor = e.editor;
|
|
||||||
var text = e.args || "";
|
|
||||||
var pos = editor.getCursorPosition();
|
var pos = editor.getCursorPosition();
|
||||||
var line = editor.session.getLine(pos.row);
|
var line = editor.session.getLine(pos.row);
|
||||||
var hasCompleter = editor.completer && editor.completer.activated;
|
|
||||||
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
|
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
|
||||||
|
// Try to find custom prefixes on the completers
|
||||||
//Try to find custom prefixes on the completers
|
editor.completers.forEach(function(completer) {
|
||||||
completers.forEach(function(completer) {
|
|
||||||
if (completer.identifierRegexps) {
|
if (completer.identifierRegexps) {
|
||||||
completer.identifierRegexps.forEach(function(identifierRegex) {
|
completer.identifierRegexps.forEach(function(identifierRegex) {
|
||||||
if (!prefix) {
|
if (!prefix && identifierRegex)
|
||||||
prefix = util.retrievePrecedingIdentifier(line, pos.column, 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
|
// We don't want to autocomplete with no prefix
|
||||||
if (e.command.name === "backspace" && !prefix) {
|
if (e.command.name === "backspace") {
|
||||||
if (hasCompleter)
|
if (hasCompleter && !getCompletionPrefix(editor))
|
||||||
editor.completer.detach();
|
editor.completer.detach();
|
||||||
}
|
}
|
||||||
else if (e.command.name === "insertstring") {
|
else if (e.command.name === "insertstring") {
|
||||||
|
var prefix = getCompletionPrefix(editor);
|
||||||
// Only autocomplete if there's a prefix that can be matched
|
// Only autocomplete if there's a prefix that can be matched
|
||||||
if (prefix && !hasCompleter) {
|
if (prefix && !hasCompleter) {
|
||||||
if (!editor.completer) {
|
if (!editor.completer) {
|
||||||
// Create new autocompleter
|
// Create new autocompleter
|
||||||
editor.completer = new Autocomplete();
|
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);
|
editor.completer.showPopup(editor);
|
||||||
} else if (!prefix && hasCompleter) {
|
} else if (!prefix && hasCompleter) {
|
||||||
// When the prefix is empty
|
// When the prefix is empty
|
||||||
|
|
@ -168,7 +173,8 @@ require("../config").defineOptions(Editor.prototype, "editor", {
|
||||||
enableBasicAutocompletion: {
|
enableBasicAutocompletion: {
|
||||||
set: function(val) {
|
set: function(val) {
|
||||||
if (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);
|
this.commands.addCommand(Autocomplete.startCommand);
|
||||||
} else {
|
} else {
|
||||||
this.commands.removeCommand(Autocomplete.startCommand);
|
this.commands.removeCommand(Autocomplete.startCommand);
|
||||||
|
|
@ -183,7 +189,8 @@ require("../config").defineOptions(Editor.prototype, "editor", {
|
||||||
enableLiveAutocompletion: {
|
enableLiveAutocompletion: {
|
||||||
set: function(val) {
|
set: function(val) {
|
||||||
if (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
|
// On each change automatically trigger the autocomplete
|
||||||
this.commands.on('afterExec', doLiveAutocomplete);
|
this.commands.on('afterExec', doLiveAutocomplete);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue