Merge branch 'tweak-autocomplete'
This commit is contained in:
commit
55886771a9
6 changed files with 55 additions and 80 deletions
|
|
@ -180,13 +180,15 @@ var Autocomplete = function() {
|
|||
|
||||
"Esc": function(editor) { editor.completer.detach(); },
|
||||
"Space": function(editor) { editor.completer.detach(); editor.insert(" ");},
|
||||
"Return": function(editor) {
|
||||
if (editor.completer.popup.getRow() == -1)
|
||||
return false;
|
||||
editor.completer.insertMatch();
|
||||
},
|
||||
"Return": function(editor) { return editor.completer.insertMatch(); },
|
||||
"Shift-Return": function(editor) { editor.completer.insertMatch(true); },
|
||||
"Tab": function(editor) { editor.completer.insertMatch(); },
|
||||
"Tab": function(editor) {
|
||||
var result = editor.completer.insertMatch();
|
||||
if (!result && !editor.tabstopManager)
|
||||
editor.completer.goTo("down");
|
||||
else
|
||||
return result;
|
||||
},
|
||||
|
||||
"PageUp": function(editor) { editor.completer.popup.gotoPageUp(); },
|
||||
"PageDown": function(editor) { editor.completer.popup.gotoPageDown(); }
|
||||
|
|
@ -208,16 +210,16 @@ var Autocomplete = function() {
|
|||
completer.getCompletions(editor, session, pos, prefix, function(err, results) {
|
||||
if (!err)
|
||||
matches = matches.concat(results);
|
||||
// Fetch prefix again, because they may have changed by now
|
||||
var pos = editor.getCursorPosition();
|
||||
var line = session.getLine(pos.row);
|
||||
callback(null, {
|
||||
prefix: util.retrievePrecedingIdentifier(line, pos.column),
|
||||
// Fetch prefix again, because they may have changed by now
|
||||
var pos = editor.getCursorPosition();
|
||||
var line = session.getLine(pos.row);
|
||||
callback(null, {
|
||||
prefix: util.retrievePrecedingIdentifier(line, pos.column, results[0] && results[0].identifierRegex),
|
||||
matches: matches,
|
||||
finished: (--total === 0)
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
return true;
|
||||
};
|
||||
|
||||
|
|
@ -269,22 +271,10 @@ var Autocomplete = function() {
|
|||
return this.detach();
|
||||
}.bind(this);
|
||||
|
||||
// Calcul prefix
|
||||
var session = this.editor.getSession();
|
||||
var pos = this.editor.getCursorPosition();
|
||||
var line = session.getLine(pos.row);
|
||||
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
|
||||
|
||||
// Results matches
|
||||
var prefix = results.prefix;
|
||||
var matches = results && results.matches;
|
||||
|
||||
if (!matches || !matches.length)
|
||||
return this.detach();
|
||||
// TODO reenable this when we have proper change tracking
|
||||
// if (matches.length == 1)
|
||||
// return this.insertMatch(matches[0]);
|
||||
|
||||
// No prefix or no results -> close
|
||||
if (!prefix || !prefix.length || !matches || !matches.length)
|
||||
return doDetach();
|
||||
|
||||
// Wrong prefix or wrong session -> ignore
|
||||
|
|
@ -328,6 +318,8 @@ Autocomplete.startCommand = {
|
|||
exec: function(editor) {
|
||||
if (!editor.completer)
|
||||
editor.completer = new Autocomplete();
|
||||
editor.completer.autoInsert =
|
||||
editor.completer.autoSelect = true;
|
||||
editor.completer.showPopup(editor);
|
||||
// needed for firefox on mac
|
||||
editor.completer.cancelContextMenu();
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ var expandSnippet = {
|
|||
if (!success)
|
||||
editor.execCommand("indent");
|
||||
},
|
||||
bindKey: "tab"
|
||||
bindKey: "Tab"
|
||||
};
|
||||
|
||||
var onChangeMode = function(e, editor) {
|
||||
|
|
@ -117,53 +117,44 @@ 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;
|
||||
//Try to find custom prefixes on the completers
|
||||
completers.forEach(function(completer) {
|
||||
if (completer.identifierRegexps) {
|
||||
completer.identifierRegexps.forEach(function(identifierRegex){
|
||||
if (!prefix) {
|
||||
prefix = util.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
// 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.autoSelect = false;
|
||||
editor.completer.autoInsert = false;
|
||||
}
|
||||
editor.completer.showPopup(editor);
|
||||
} else if (!prefix && hasCompleter) {
|
||||
// When the prefix is empty
|
||||
// close the autocomplete dialog
|
||||
editor.completer.detach();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -206,4 +197,4 @@ require("../config").defineOptions(Editor.prototype, "editor", {
|
|||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -26,9 +26,6 @@ var CSharpHighlightRules = function() {
|
|||
token : "comment", // multi line comment
|
||||
regex : "\\/\\*",
|
||||
next : "comment"
|
||||
}, {
|
||||
token : "string.regexp",
|
||||
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
|
||||
}, {
|
||||
token : "string", // character
|
||||
regex : /'(?:.|\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n]))'/
|
||||
|
|
|
|||
|
|
@ -72,9 +72,6 @@ var JavaHighlightRules = function() {
|
|||
token : "comment", // multi line comment
|
||||
regex : "\\/\\*",
|
||||
next : "comment"
|
||||
}, {
|
||||
token : "string.regexp",
|
||||
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
|
||||
}, {
|
||||
token : "string", // single line
|
||||
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
||||
|
|
|
|||
|
|
@ -379,7 +379,7 @@ var SnippetManager = function() {
|
|||
scope = scope.split("/").pop();
|
||||
if (scope === "html" || scope === "php") {
|
||||
// PHP is actually HTML
|
||||
if (scope === "php")
|
||||
if (scope === "php" && !editor.session.$mode.inlinePhp)
|
||||
scope = "html";
|
||||
var c = editor.getCursorPosition()
|
||||
var state = editor.session.getState(c.row);
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue