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(); },
|
"Esc": function(editor) { editor.completer.detach(); },
|
||||||
"Space": function(editor) { editor.completer.detach(); editor.insert(" ");},
|
"Space": function(editor) { editor.completer.detach(); editor.insert(" ");},
|
||||||
"Return": function(editor) {
|
"Return": function(editor) { return editor.completer.insertMatch(); },
|
||||||
if (editor.completer.popup.getRow() == -1)
|
|
||||||
return false;
|
|
||||||
editor.completer.insertMatch();
|
|
||||||
},
|
|
||||||
"Shift-Return": function(editor) { editor.completer.insertMatch(true); },
|
"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(); },
|
"PageUp": function(editor) { editor.completer.popup.gotoPageUp(); },
|
||||||
"PageDown": function(editor) { editor.completer.popup.gotoPageDown(); }
|
"PageDown": function(editor) { editor.completer.popup.gotoPageDown(); }
|
||||||
|
|
@ -208,16 +210,16 @@ var Autocomplete = function() {
|
||||||
completer.getCompletions(editor, session, pos, prefix, function(err, results) {
|
completer.getCompletions(editor, session, pos, prefix, function(err, results) {
|
||||||
if (!err)
|
if (!err)
|
||||||
matches = matches.concat(results);
|
matches = matches.concat(results);
|
||||||
// Fetch prefix again, because they may have changed by now
|
// Fetch prefix again, because they may have changed by now
|
||||||
var pos = editor.getCursorPosition();
|
var pos = editor.getCursorPosition();
|
||||||
var line = session.getLine(pos.row);
|
var line = session.getLine(pos.row);
|
||||||
callback(null, {
|
callback(null, {
|
||||||
prefix: util.retrievePrecedingIdentifier(line, pos.column),
|
prefix: util.retrievePrecedingIdentifier(line, pos.column, results[0] && results[0].identifierRegex),
|
||||||
matches: matches,
|
matches: matches,
|
||||||
finished: (--total === 0)
|
finished: (--total === 0)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -269,22 +271,10 @@ var Autocomplete = function() {
|
||||||
return this.detach();
|
return this.detach();
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
// Calcul prefix
|
var prefix = results.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 matches = results && results.matches;
|
var matches = results && results.matches;
|
||||||
|
|
||||||
if (!matches || !matches.length)
|
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();
|
return doDetach();
|
||||||
|
|
||||||
// Wrong prefix or wrong session -> ignore
|
// Wrong prefix or wrong session -> ignore
|
||||||
|
|
@ -328,6 +318,8 @@ Autocomplete.startCommand = {
|
||||||
exec: function(editor) {
|
exec: function(editor) {
|
||||||
if (!editor.completer)
|
if (!editor.completer)
|
||||||
editor.completer = new Autocomplete();
|
editor.completer = new Autocomplete();
|
||||||
|
editor.completer.autoInsert =
|
||||||
|
editor.completer.autoSelect = true;
|
||||||
editor.completer.showPopup(editor);
|
editor.completer.showPopup(editor);
|
||||||
// needed for firefox on mac
|
// needed for firefox on mac
|
||||||
editor.completer.cancelContextMenu();
|
editor.completer.cancelContextMenu();
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ var expandSnippet = {
|
||||||
if (!success)
|
if (!success)
|
||||||
editor.execCommand("indent");
|
editor.execCommand("indent");
|
||||||
},
|
},
|
||||||
bindKey: "tab"
|
bindKey: "Tab"
|
||||||
};
|
};
|
||||||
|
|
||||||
var onChangeMode = function(e, editor) {
|
var onChangeMode = function(e, editor) {
|
||||||
|
|
@ -117,53 +117,44 @@ 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
|
//Try to find custom prefixes on the completers
|
||||||
if(prefix !== '' && !(hasCompleter)) {
|
completers.forEach(function(completer) {
|
||||||
if (!editor.completer) {
|
if (completer.identifierRegexps) {
|
||||||
// Create new autocompleter
|
completer.identifierRegexps.forEach(function(identifierRegex){
|
||||||
editor.completer = new Autocomplete();
|
if (!prefix) {
|
||||||
|
prefix = util.retrievePrecedingIdentifier(line, pos.column, identifierRegex);
|
||||||
// Disable autoInsert
|
}
|
||||||
editor.completer.autoInsert = false;
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
editor.completer.showPopup(editor);
|
// We don't want to autocomplete with no prefix
|
||||||
// needed for firefox on mac
|
if (e.command.name === "backspace" && !prefix) {
|
||||||
editor.completer.cancelContextMenu();
|
if (hasCompleter)
|
||||||
|
editor.completer.detach();
|
||||||
} else if(prefix === '' && hasCompleter) {
|
}
|
||||||
// When the prefix is empty
|
else if (e.command.name === "insertstring") {
|
||||||
// close the autocomplete dialog
|
// Only autocomplete if there's a prefix that can be matched
|
||||||
editor.completer.detach();
|
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
|
token : "comment", // multi line comment
|
||||||
regex : "\\/\\*",
|
regex : "\\/\\*",
|
||||||
next : "comment"
|
next : "comment"
|
||||||
}, {
|
|
||||||
token : "string.regexp",
|
|
||||||
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
|
|
||||||
}, {
|
}, {
|
||||||
token : "string", // character
|
token : "string", // character
|
||||||
regex : /'(?:.|\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n]))'/
|
regex : /'(?:.|\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n]))'/
|
||||||
|
|
|
||||||
|
|
@ -72,9 +72,6 @@ var JavaHighlightRules = function() {
|
||||||
token : "comment", // multi line comment
|
token : "comment", // multi line comment
|
||||||
regex : "\\/\\*",
|
regex : "\\/\\*",
|
||||||
next : "comment"
|
next : "comment"
|
||||||
}, {
|
|
||||||
token : "string.regexp",
|
|
||||||
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
|
|
||||||
}, {
|
}, {
|
||||||
token : "string", // single line
|
token : "string", // single line
|
||||||
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
||||||
|
|
|
||||||
|
|
@ -379,7 +379,7 @@ var SnippetManager = function() {
|
||||||
scope = scope.split("/").pop();
|
scope = scope.split("/").pop();
|
||||||
if (scope === "html" || scope === "php") {
|
if (scope === "html" || scope === "php") {
|
||||||
// PHP is actually HTML
|
// PHP is actually HTML
|
||||||
if (scope === "php")
|
if (scope === "php" && !editor.session.$mode.inlinePhp)
|
||||||
scope = "html";
|
scope = "html";
|
||||||
var c = editor.getCursorPosition()
|
var c = editor.getCursorPosition()
|
||||||
var state = editor.session.getState(c.row);
|
var state = editor.session.getState(c.row);
|
||||||
|
|
|
||||||
|
|
@ -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";
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue