Work around ace's autocomplete initialization not taking tokenization into account but rather rely on word boundaries

This commit is contained in:
Boaz Leskes 2014-01-22 14:29:51 +01:00
parent 1ebb6e45cf
commit 4bf8615d63
2 changed files with 21 additions and 4 deletions

View file

@ -1141,11 +1141,25 @@ define([
}
function getCompletions(editor, session, pos, prefix, callback) {
function getCompletions(aceEditor, session, pos, prefix, callback) {
// this is hacky, but there is at the moment no settings/way to do it differently
editor.completer.autoInsert = false;
aceEditor.completer.autoInsert = false;
var token = aceEditor.getSession().getTokenAt(pos.row, pos.column);
if (!editor.parser.isEmptyToken(token)) {
// Ace doesn't care about tokenization when calculating prefix. It will thus stop on . in keys names.
if (token.value.indexOf('"') == 0) {
aceEditor.completer.base.column = token.start+1;
} else {
aceEditor.completer.base.column = token.start;
}
var context = getAutoCompleteContext(editor, session, pos);
// we have to trigger a render update to make the new prefix take affect.
setTimeout(function () { aceEditor.completer.changeListener(); }, 0);
}
var context = getAutoCompleteContext(aceEditor, session, pos);
if (!context) {
callback(null, []);
} else {

View file

@ -53,7 +53,10 @@ define([
// allow ace rendering to move cursor so it will be seen during test - handy for debugging.
setTimeout(function () {
input.completer = {}; // mimic auto complete
input.completer = {
base: {},
changeListener : function () {}
}; // mimic auto complete
input.autocomplete.completer.getCompletions(input, input.getSession(), test.cursor, "",
function (err, terms) {