hide the popup when editor is scrolled
This commit is contained in:
parent
36c166b9ed
commit
35a9dc5ba1
1 changed files with 32 additions and 35 deletions
|
|
@ -43,6 +43,7 @@ var Autocomplete = function() {
|
|||
this.blurListener = this.blurListener.bind(this);
|
||||
this.changeListener = this.changeListener.bind(this);
|
||||
this.mousedownListener = this.mousedownListener.bind(this);
|
||||
this.mousewheelListener = this.mousewheelListener.bind(this);
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
|
@ -82,12 +83,12 @@ var Autocomplete = function() {
|
|||
if (this.popup)
|
||||
this.popup.hide();
|
||||
|
||||
this.editor.completer.activated = false;
|
||||
this.activated = false;
|
||||
};
|
||||
|
||||
this.changeListener = function(e) {
|
||||
if (this.editor.completer.activated)
|
||||
this.complete(this.editor);
|
||||
if (this.activated)
|
||||
this.showPopup(this.editor);
|
||||
else
|
||||
this.detach();
|
||||
};
|
||||
|
|
@ -98,13 +99,11 @@ var Autocomplete = function() {
|
|||
};
|
||||
|
||||
this.mousedownListener = function(e) {
|
||||
var mouseX = e.clientX, mouseY = e.clientY;
|
||||
var newRow = this.editor.renderer.pixelToScreenCoordinates(mouseX, mouseY).row;
|
||||
var currentRow = e.editor.getCursorPosition().row;
|
||||
this.detach();
|
||||
};
|
||||
|
||||
if (newRow !== currentRow) {
|
||||
this.detach();
|
||||
}
|
||||
this.mousewheelListener = function(e) {
|
||||
this.detach();
|
||||
};
|
||||
|
||||
this.goTo = function(where) {
|
||||
|
|
@ -126,15 +125,16 @@ var Autocomplete = function() {
|
|||
if (!data)
|
||||
data = this.popup.getData(this.popup.getRow());
|
||||
if (!data)
|
||||
return false;
|
||||
if (data.completer && data.completer.insertMatch) {
|
||||
data.completer.insertMatch(this.editor);
|
||||
} else {
|
||||
if (data.value)
|
||||
data = data.value;
|
||||
this.editor.removeWordLeft();
|
||||
this.editor.insert(data);
|
||||
}
|
||||
return false;
|
||||
if (data.completer && data.completer.insertMatch) {
|
||||
data.completer.insertMatch(this.editor);
|
||||
} else {
|
||||
if (data.value)
|
||||
data = data.value;
|
||||
if (data.prefix)
|
||||
this.editor.removeWordLeft();
|
||||
this.editor.insert(data);
|
||||
}
|
||||
};
|
||||
|
||||
this.commands = {
|
||||
|
|
@ -153,13 +153,13 @@ var Autocomplete = function() {
|
|||
"PageDown": function(editor) { editor.completer.popup.gotoPageUp(); }
|
||||
};
|
||||
|
||||
this.getCompletions = function(editor, callback) {
|
||||
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);
|
||||
|
||||
|
||||
var matches = [];
|
||||
util.parForEach(editor.completers, function(completer, next) {
|
||||
completer.getCompletions(session, pos, prefix, function(err, results) {
|
||||
|
|
@ -178,8 +178,8 @@ var Autocomplete = function() {
|
|||
});
|
||||
return true;
|
||||
};
|
||||
|
||||
this.complete = function(editor) {
|
||||
|
||||
this.showPopup = function(editor) {
|
||||
if (this.editor)
|
||||
this.detach();
|
||||
|
||||
|
|
@ -195,20 +195,20 @@ var Autocomplete = function() {
|
|||
editor.on("blur", this.blurListener);
|
||||
editor.on("mousedown", this.mousedownListener);
|
||||
|
||||
this.getCompletions(this.editor, function(err, results) {
|
||||
var matches = results && results.matches;
|
||||
if (!matches || !matches.length)
|
||||
return this.detach();
|
||||
if (matches.length == 1)
|
||||
return this.insertMatch(matches[0]);
|
||||
this.gatherCompletions(this.editor, function(err, results) {
|
||||
var matches = results && results.matches;
|
||||
if (!matches || !matches.length)
|
||||
return this.detach();
|
||||
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.openPopup(editor);
|
||||
this.popup.setHighlight(results.prefix);
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
|
||||
this.cancelContextMenu = function() {
|
||||
var stop = function(e) {
|
||||
this.editor.off("nativecontextmenu", stop);
|
||||
|
|
@ -218,8 +218,6 @@ var Autocomplete = function() {
|
|||
setTimeout(stop, 10);
|
||||
this.editor.on("nativecontextmenu", stop);
|
||||
};
|
||||
|
||||
this.completers = [];
|
||||
|
||||
}).call(Autocomplete.prototype);
|
||||
|
||||
|
|
@ -228,8 +226,7 @@ Autocomplete.startCommand = {
|
|||
exec: function(editor) {
|
||||
if (!editor.completer)
|
||||
editor.completer = new Autocomplete();
|
||||
editor.completer.complete(editor);
|
||||
editor.completer.activated = true;
|
||||
editor.completer.showPopup(editor);
|
||||
// needed for firefox on mac
|
||||
editor.completer.cancelContextMenu();
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue