Use event afterExec instead of change for live autocomplete
This commit is contained in:
parent
df99195544
commit
110eb26f96
1 changed files with 11 additions and 8 deletions
|
|
@ -115,24 +115,27 @@ var loadSnippetFile = function(id) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var onChangeAutocomplete = function(e, editor) {
|
var onChangeAutocomplete = function(e) {
|
||||||
|
var editor = e.editor;
|
||||||
var session = editor.getSession();
|
var session = editor.getSession();
|
||||||
var pos = editor.getCursorPosition();
|
var pos = editor.getCursorPosition();
|
||||||
var line = session.getLine(pos.row);
|
var line = session.getLine(pos.row);
|
||||||
var hasCompleter = (editor.completer && editor.completer.activated);
|
var hasCompleter = (editor.completer && editor.completer.activated);
|
||||||
|
|
||||||
|
var text = e.args || "";
|
||||||
|
|
||||||
// Detect paste (poor man's paste detection)
|
// Detect paste (poor man's paste detection)
|
||||||
var typing = !(
|
var typing = !(
|
||||||
(
|
(
|
||||||
e.data.action === 'insertText' &&
|
e.command.name === "insertstring" &&
|
||||||
e.data.text.length > 1
|
text.length > 1
|
||||||
) ||
|
) ||
|
||||||
e.data.action !== 'insertText'
|
e.command.name !== "insertstring"
|
||||||
);
|
);
|
||||||
|
|
||||||
// We don't want to autocomplete with no prefix
|
// We don't want to autocomplete with no prefix
|
||||||
if(
|
if(
|
||||||
e.data.action === 'removeText' &&
|
e.command.name === 'backspace' &&
|
||||||
util.retrievePrecedingIdentifier(line, pos.column) === ''
|
util.retrievePrecedingIdentifier(line, pos.column) === ''
|
||||||
) {
|
) {
|
||||||
if(hasCompleter) editor.completer.detach();
|
if(hasCompleter) editor.completer.detach();
|
||||||
|
|
@ -145,8 +148,8 @@ var onChangeAutocomplete = function(e, editor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append added text to the line
|
// Append added text to the line
|
||||||
line += e.data.text;
|
line += text;
|
||||||
pos.column += e.data.text.length;
|
pos.column += text.length;
|
||||||
|
|
||||||
// The prefix to autocomplete for
|
// The prefix to autocomplete for
|
||||||
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
|
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
|
||||||
|
|
@ -181,7 +184,7 @@ require("../config").defineOptions(Editor.prototype, "editor", {
|
||||||
this.commands.addCommand(Autocomplete.startCommand);
|
this.commands.addCommand(Autocomplete.startCommand);
|
||||||
|
|
||||||
// On each change automatically trigger the autocomplete
|
// On each change automatically trigger the autocomplete
|
||||||
this.on('change', onChangeAutocomplete);
|
this.commands.on('afterExec', onChangeAutocomplete);
|
||||||
} else {
|
} else {
|
||||||
this.removeListener('change', onChangeAutocomplete);
|
this.removeListener('change', onChangeAutocomplete);
|
||||||
this.commands.removeCommand(Autocomplete.startCommand);
|
this.commands.removeCommand(Autocomplete.startCommand);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue