revert to simpler range tracking model for now
This commit is contained in:
parent
35a9dc5ba1
commit
ac9bb727cc
1 changed files with 31 additions and 18 deletions
|
|
@ -35,6 +35,7 @@ var HashHandler = require("./keyboard/hash_handler").HashHandler;
|
||||||
var AcePopup = require("./autocomplete/popup").AcePopup;
|
var AcePopup = require("./autocomplete/popup").AcePopup;
|
||||||
var util = require("./autocomplete/util");
|
var util = require("./autocomplete/util");
|
||||||
var event = require("./lib/event");
|
var event = require("./lib/event");
|
||||||
|
var lang = require("./lib/lang");
|
||||||
|
|
||||||
var Autocomplete = function() {
|
var Autocomplete = function() {
|
||||||
this.keyboardHandler = new HashHandler();
|
this.keyboardHandler = new HashHandler();
|
||||||
|
|
@ -44,6 +45,10 @@ var Autocomplete = function() {
|
||||||
this.changeListener = this.changeListener.bind(this);
|
this.changeListener = this.changeListener.bind(this);
|
||||||
this.mousedownListener = this.mousedownListener.bind(this);
|
this.mousedownListener = this.mousedownListener.bind(this);
|
||||||
this.mousewheelListener = this.mousewheelListener.bind(this);
|
this.mousewheelListener = this.mousewheelListener.bind(this);
|
||||||
|
|
||||||
|
this.changeTimer = lang.delayedCall(function() {
|
||||||
|
this.updateCompletions(true);
|
||||||
|
}.bind(this))
|
||||||
};
|
};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
@ -55,22 +60,23 @@ var Autocomplete = function() {
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
this.openPopup = function(editor) {
|
this.openPopup = function(editor, keepPopupPosition) {
|
||||||
if (!this.popup)
|
if (!this.popup)
|
||||||
this.$init();
|
this.$init();
|
||||||
|
|
||||||
this.popup.setData(this.completions.filtered);
|
this.popup.setData(this.completions.filtered);
|
||||||
|
|
||||||
var renderer = editor.renderer;
|
var renderer = editor.renderer;
|
||||||
var lineHeight = renderer.layerConfig.lineHeight;
|
if (!keepPopupPosition) {
|
||||||
var pos = renderer.$cursorLayer.getPixelPosition(null, true);
|
var lineHeight = renderer.layerConfig.lineHeight;
|
||||||
var rect = editor.container.getBoundingClientRect();
|
var pos = renderer.$cursorLayer.getPixelPosition(null, true);
|
||||||
pos.top += rect.top - renderer.layerConfig.offset;
|
var rect = editor.container.getBoundingClientRect();
|
||||||
pos.left += rect.left;
|
pos.top += rect.top - renderer.layerConfig.offset;
|
||||||
pos.left += renderer.$gutterLayer.gutterWidth;
|
pos.left += rect.left;
|
||||||
|
pos.left += renderer.$gutterLayer.gutterWidth;
|
||||||
this.popup.show(pos, lineHeight);
|
|
||||||
|
|
||||||
|
this.popup.show(pos, lineHeight);
|
||||||
|
}
|
||||||
renderer.updateText();
|
renderer.updateText();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -79,7 +85,8 @@ var Autocomplete = function() {
|
||||||
this.editor.removeEventListener("changeSelection", this.changeListener);
|
this.editor.removeEventListener("changeSelection", this.changeListener);
|
||||||
this.editor.removeEventListener("blur", this.changeListener);
|
this.editor.removeEventListener("blur", this.changeListener);
|
||||||
this.editor.removeEventListener("mousedown", this.changeListener);
|
this.editor.removeEventListener("mousedown", this.changeListener);
|
||||||
|
this.changeTimer.cancel();
|
||||||
|
|
||||||
if (this.popup)
|
if (this.popup)
|
||||||
this.popup.hide();
|
this.popup.hide();
|
||||||
|
|
||||||
|
|
@ -88,7 +95,7 @@ var Autocomplete = function() {
|
||||||
|
|
||||||
this.changeListener = function(e) {
|
this.changeListener = function(e) {
|
||||||
if (this.activated)
|
if (this.activated)
|
||||||
this.showPopup(this.editor);
|
this.changeTimer.schedule();
|
||||||
else
|
else
|
||||||
this.detach();
|
this.detach();
|
||||||
};
|
};
|
||||||
|
|
@ -131,8 +138,8 @@ var Autocomplete = function() {
|
||||||
} else {
|
} else {
|
||||||
if (data.value)
|
if (data.value)
|
||||||
data = data.value;
|
data = data.value;
|
||||||
if (data.prefix)
|
if (this.completions.filterText)
|
||||||
this.editor.removeWordLeft();
|
this.editor.removeWordLeft();
|
||||||
this.editor.insert(data);
|
this.editor.insert(data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -182,6 +189,8 @@ var Autocomplete = function() {
|
||||||
this.showPopup = function(editor) {
|
this.showPopup = function(editor) {
|
||||||
if (this.editor)
|
if (this.editor)
|
||||||
this.detach();
|
this.detach();
|
||||||
|
|
||||||
|
this.activated = true;
|
||||||
|
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
if (editor.completer != this) {
|
if (editor.completer != this) {
|
||||||
|
|
@ -194,17 +203,21 @@ var Autocomplete = function() {
|
||||||
editor.on("changeSelection", this.changeListener);
|
editor.on("changeSelection", this.changeListener);
|
||||||
editor.on("blur", this.blurListener);
|
editor.on("blur", this.blurListener);
|
||||||
editor.on("mousedown", this.mousedownListener);
|
editor.on("mousedown", this.mousedownListener);
|
||||||
|
this.updateCompletions();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateCompletions = function(keepPopupPosition) {
|
||||||
this.gatherCompletions(this.editor, function(err, results) {
|
this.gatherCompletions(this.editor, function(err, results) {
|
||||||
var matches = results && results.matches;
|
var matches = results && results.matches;
|
||||||
if (!matches || !matches.length)
|
if (!matches || !matches.length)
|
||||||
return this.detach();
|
return this.detach();
|
||||||
if (matches.length == 1)
|
// TODO reenable this when we have proper change tracking
|
||||||
return this.insertMatch(matches[0]);
|
// if (matches.length == 1)
|
||||||
|
// return this.insertMatch(matches[0]);
|
||||||
|
|
||||||
this.completions = new FilteredList(matches);
|
this.completions = new FilteredList(matches);
|
||||||
this.completions.setFilter(results.prefix);
|
this.completions.setFilter(results.prefix);
|
||||||
this.openPopup(editor);
|
this.openPopup(this.editor, keepPopupPosition);
|
||||||
this.popup.setHighlight(results.prefix);
|
this.popup.setHighlight(results.prefix);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
|
|
@ -243,7 +256,7 @@ var FilteredList = function(array, mutateData) {
|
||||||
};
|
};
|
||||||
(function(){
|
(function(){
|
||||||
this.setFilter = function(str) {
|
this.setFilter = function(str) {
|
||||||
|
this.filterText = str;
|
||||||
};
|
};
|
||||||
|
|
||||||
}).call(FilteredList.prototype);
|
}).call(FilteredList.prototype);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue