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 pos = editor.getCursorPosition();
|
||||
var line = session.getLine(pos.row);
|
||||
var hasCompleter = (editor.completer && editor.completer.activated);
|
||||
|
||||
var text = e.args || "";
|
||||
|
||||
// Detect paste (poor man's paste detection)
|
||||
var typing = !(
|
||||
(
|
||||
e.data.action === 'insertText' &&
|
||||
e.data.text.length > 1
|
||||
e.command.name === "insertstring" &&
|
||||
text.length > 1
|
||||
) ||
|
||||
e.data.action !== 'insertText'
|
||||
e.command.name !== "insertstring"
|
||||
);
|
||||
|
||||
// We don't want to autocomplete with no prefix
|
||||
if(
|
||||
e.data.action === 'removeText' &&
|
||||
e.command.name === 'backspace' &&
|
||||
util.retrievePrecedingIdentifier(line, pos.column) === ''
|
||||
) {
|
||||
if(hasCompleter) editor.completer.detach();
|
||||
|
|
@ -145,8 +148,8 @@ var onChangeAutocomplete = function(e, editor) {
|
|||
}
|
||||
|
||||
// Append added text to the line
|
||||
line += e.data.text;
|
||||
pos.column += e.data.text.length;
|
||||
line += text;
|
||||
pos.column += text.length;
|
||||
|
||||
// The prefix to autocomplete for
|
||||
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
|
||||
|
|
@ -181,7 +184,7 @@ require("../config").defineOptions(Editor.prototype, "editor", {
|
|||
this.commands.addCommand(Autocomplete.startCommand);
|
||||
|
||||
// On each change automatically trigger the autocomplete
|
||||
this.on('change', onChangeAutocomplete);
|
||||
this.commands.on('afterExec', onChangeAutocomplete);
|
||||
} else {
|
||||
this.removeListener('change', onChangeAutocomplete);
|
||||
this.commands.removeCommand(Autocomplete.startCommand);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue