Cleanup autocomplete.js
Consistently use .bind(this) instead of that = this
This commit is contained in:
parent
0e256ce80d
commit
c52278a64e
1 changed files with 16 additions and 17 deletions
|
|
@ -47,7 +47,7 @@ var Autocomplete = function() {
|
|||
this.changeListener = this.changeListener.bind(this);
|
||||
this.mousedownListener = this.mousedownListener.bind(this);
|
||||
this.mousewheelListener = this.mousewheelListener.bind(this);
|
||||
|
||||
|
||||
this.changeTimer = lang.delayedCall(function() {
|
||||
this.updateCompletions(true);
|
||||
}.bind(this))
|
||||
|
|
@ -77,10 +77,10 @@ var Autocomplete = function() {
|
|||
this.popup.setFontSize(editor.getFontSize());
|
||||
|
||||
var lineHeight = renderer.layerConfig.lineHeight;
|
||||
|
||||
var pos = renderer.$cursorLayer.getPixelPosition(this.base, true);
|
||||
|
||||
var pos = renderer.$cursorLayer.getPixelPosition(this.base, true);
|
||||
pos.left -= this.popup.getTextLeftOffset();
|
||||
|
||||
|
||||
var rect = editor.container.getBoundingClientRect();
|
||||
pos.top += rect.top - renderer.layerConfig.offset;
|
||||
pos.left += rect.left - editor.renderer.scrollLeft;
|
||||
|
|
@ -101,7 +101,7 @@ var Autocomplete = function() {
|
|||
if (this.popup && this.popup.isOpen) {
|
||||
this.gatherCompletionsId = this.gatherCompletionsId + 1;
|
||||
}
|
||||
|
||||
|
||||
if (this.popup)
|
||||
this.popup.hide();
|
||||
|
||||
|
|
@ -190,10 +190,10 @@ var Autocomplete = function() {
|
|||
this.gatherCompletions = function(editor, callback) {
|
||||
var session = editor.getSession();
|
||||
var pos = editor.getCursorPosition();
|
||||
|
||||
|
||||
var line = session.getLine(pos.row);
|
||||
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
|
||||
|
||||
|
||||
this.base = editor.getCursorPosition();
|
||||
this.base.column -= prefix.length;
|
||||
|
||||
|
|
@ -216,7 +216,7 @@ var Autocomplete = function() {
|
|||
this.showPopup = function(editor) {
|
||||
if (this.editor)
|
||||
this.detach();
|
||||
|
||||
|
||||
this.activated = true;
|
||||
|
||||
this.editor = editor;
|
||||
|
|
@ -231,12 +231,11 @@ var Autocomplete = function() {
|
|||
editor.on("blur", this.blurListener);
|
||||
editor.on("mousedown", this.mousedownListener);
|
||||
editor.on("mousewheel", this.mousewheelListener);
|
||||
|
||||
|
||||
this.updateCompletions();
|
||||
};
|
||||
|
||||
|
||||
this.updateCompletions = function(keepPopupPosition) {
|
||||
var that = this;
|
||||
if (keepPopupPosition && this.base && this.completions) {
|
||||
var pos = this.editor.getCursorPosition();
|
||||
var prefix = this.editor.session.getTextRange({start: this.base, end: pos});
|
||||
|
|
@ -262,14 +261,14 @@ var Autocomplete = function() {
|
|||
}.bind(this);
|
||||
|
||||
// Calcul prefix
|
||||
var session = that.editor.getSession();
|
||||
var pos = that.editor.getCursorPosition();
|
||||
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;
|
||||
// TODO reenable this when we have proper change tracking
|
||||
// TODO reenable this when we have proper change tracking
|
||||
// if (matches.length == 1)
|
||||
// return this.insertMatch(matches[0]);
|
||||
|
||||
|
|
@ -343,16 +342,16 @@ var FilteredList = function(array, filterText, mutateData) {
|
|||
matches = matches.sort(function(a, b) {
|
||||
return b.exactMatch - a.exactMatch || b.score - a.score;
|
||||
});
|
||||
|
||||
|
||||
// make unique
|
||||
var prev = null;
|
||||
matches = matches.filter(function(item){
|
||||
var caption = item.value || item.caption || item.snippet;
|
||||
var caption = item.value || item.caption || item.snippet;
|
||||
if (caption === prev) return false;
|
||||
prev = caption;
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
this.filtered = matches;
|
||||
};
|
||||
this.filterCompletions = function(items, needle) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue