fix regression for autocomplete with empty prefix

This commit is contained in:
nightwing 2014-04-02 00:03:53 +04:00
commit a188ac7fa6
3 changed files with 24 additions and 48 deletions

View file

@ -283,8 +283,7 @@ var Autocomplete = function() {
// if (matches.length == 1) // if (matches.length == 1)
// return this.insertMatch(matches[0]); // return this.insertMatch(matches[0]);
// No prefix or no results -> close if (!matches || !matches.length)
if (!prefix || !prefix.length || !matches || !matches.length)
return doDetach(); return doDetach();
// Wrong prefix or wrong session -> ignore // Wrong prefix or wrong session -> ignore

View file

@ -117,53 +117,32 @@ var loadSnippetFile = function(id) {
var doLiveAutocomplete = function(e) { var doLiveAutocomplete = function(e) {
var editor = e.editor; 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 || ""; var text = e.args || "";
var pos = editor.getCursorPosition();
// Is the user entering text var line = editor.session.getLine(pos.row);
// we only want to automatically show the autocomplete dialog var hasCompleter = editor.completer && editor.completer.activated;
// whenever the user is typing in text not pasting, deleting, ...
var typing = (e.command.name === "insertstring" && text.length === 1);
// We don't want to autocomplete with no prefix
if(
e.command.name === 'backspace' &&
util.retrievePrecedingIdentifier(line, pos.column) === ''
) {
if(hasCompleter) editor.completer.detach();
return;
}
// we don't want to autocomplete on paste events
if(!typing) {
return;
}
// The prefix to autocomplete for
var prefix = util.retrievePrecedingIdentifier(line, pos.column); var prefix = util.retrievePrecedingIdentifier(line, pos.column);
// Only autocomplete if there's a prefix that can be matched // We don't want to autocomplete with no prefix
if(prefix !== '' && !(hasCompleter)) { if (e.command.name === "backspace" && !prefix) {
if (!editor.completer) { if (hasCompleter)
// Create new autocompleter editor.completer.detach();
editor.completer = new Autocomplete(); }
else if (e.command.name === "insertstring") {
// Disable autoInsert // Only autocomplete if there's a prefix that can be matched
editor.completer.autoInsert = false; if (prefix && !hasCompleter) {
if (!editor.completer) {
// Create new autocompleter
editor.completer = new Autocomplete();
// Disable autoInsert
editor.completer.autoInsert = false;
}
editor.completer.showPopup(editor);
} else if (!prefix && hasCompleter) {
// When the prefix is empty
// close the autocomplete dialog
editor.completer.detach();
} }
editor.completer.showPopup(editor);
// needed for firefox on mac
editor.completer.cancelContextMenu();
} else if(prefix === '' && hasCompleter) {
// When the prefix is empty
// close the autocomplete dialog
editor.completer.detach();
} }
}; };

View file

@ -1,9 +1,7 @@
define(function(require, exports, module) { define(function(require, exports, module) {
"use strict"; "use strict";
exports.snippetText = require("../requirejs/text!./javascript-jquery.snippets") exports.snippetText = require("../requirejs/text!./javascript.snippets");
+ "\n"
+ require("../requirejs/text!./javascript.snippets");
exports.scope = "javascript"; exports.scope = "javascript";
}); });