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)
// return this.insertMatch(matches[0]);
// No prefix or no results -> close
if (!prefix || !prefix.length || !matches || !matches.length)
if (!matches || !matches.length)
return doDetach();
// Wrong prefix or wrong session -> ignore

View file

@ -117,53 +117,32 @@ var loadSnippetFile = function(id) {
var doLiveAutocomplete = 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 || "";
// Is the user entering text
// we only want to automatically show the autocomplete dialog
// 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 pos = editor.getCursorPosition();
var line = editor.session.getLine(pos.row);
var hasCompleter = editor.completer && editor.completer.activated;
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
// 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.autoInsert = false;
// We don't want to autocomplete with no prefix
if (e.command.name === "backspace" && !prefix) {
if (hasCompleter)
editor.completer.detach();
}
else if (e.command.name === "insertstring") {
// 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.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) {
"use strict";
exports.snippetText = require("../requirejs/text!./javascript-jquery.snippets")
+ "\n"
+ require("../requirejs/text!./javascript.snippets");
exports.snippetText = require("../requirejs/text!./javascript.snippets");
exports.scope = "javascript";
});