add .getCompletions method to text mode
This commit is contained in:
parent
76fd4b1358
commit
a5f4ecf597
2 changed files with 21 additions and 15 deletions
|
|
@ -37,19 +37,10 @@ var config = require("../config");
|
||||||
|
|
||||||
var textCompleter = require("../autocomplete/text_completer");
|
var textCompleter = require("../autocomplete/text_completer");
|
||||||
var keyWordCompleter = {
|
var keyWordCompleter = {
|
||||||
getCompletions: function(session, pos, prefix, callback) {
|
getCompletions: function(editor, session, pos, prefix, callback) {
|
||||||
var keywords = session.$mode.$keywordList || [];
|
var state = editor.session.getState(pos.row);
|
||||||
keywords = keywords.filter(function(w) {
|
var completions = session.$mode.getCompletions(state, session, pos, prefix);
|
||||||
return w.lastIndexOf(prefix, 0) == 0;
|
callback(null, completions);
|
||||||
});
|
|
||||||
callback(null, keywords.map(function(word) {
|
|
||||||
return {
|
|
||||||
name: word,
|
|
||||||
value: word,
|
|
||||||
score: 0,
|
|
||||||
meta: "keyword"
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,7 @@ var Mode = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var delegations = ['toggleCommentLines', 'getNextLineIndent', 'checkOutdent', 'autoOutdent', 'transformAction'];
|
var delegations = ['toggleCommentLines', 'getNextLineIndent', 'checkOutdent', 'autoOutdent', 'transformAction', 'getCompletions'];
|
||||||
|
|
||||||
for (var i = 0; i < delegations.length; i++) {
|
for (var i = 0; i < delegations.length; i++) {
|
||||||
(function(scope) {
|
(function(scope) {
|
||||||
|
|
@ -356,7 +356,22 @@ var Mode = function() {
|
||||||
return this.$keywordList;
|
return this.$keywordList;
|
||||||
return completionKeywords.concat(this.$keywordList || []);
|
return completionKeywords.concat(this.$keywordList || []);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getCompletions = function(state, session, pos, prefix) {
|
||||||
|
var keywords = this.$keywordList || [];
|
||||||
|
keywords = keywords.filter(function(w) {
|
||||||
|
return w.lastIndexOf(prefix, 0) == 0;
|
||||||
|
});
|
||||||
|
return keywords.map(function(word) {
|
||||||
|
return {
|
||||||
|
name: word,
|
||||||
|
value: word,
|
||||||
|
score: 0,
|
||||||
|
meta: "keyword"
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
exports.Mode = Mode;
|
exports.Mode = Mode;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue