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,54 +117,33 @@ 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);
// 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 // 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 // Disable autoInsert
editor.completer.autoInsert = false; editor.completer.autoInsert = false;
} }
editor.completer.showPopup(editor); editor.completer.showPopup(editor);
// needed for firefox on mac } else if (!prefix && hasCompleter) {
editor.completer.cancelContextMenu();
} else if(prefix === '' && hasCompleter) {
// When the prefix is empty // When the prefix is empty
// close the autocomplete dialog // close the autocomplete dialog
editor.completer.detach(); editor.completer.detach();
} }
}
}; };
var Editor = require("../editor").Editor; var Editor = require("../editor").Editor;

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";
}); });