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.blurListener = this.blurListener.bind(this);
|
||||||
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
@ -82,12 +83,12 @@ var Autocomplete = function() {
|
||||||
if (this.popup)
|
if (this.popup)
|
||||||
this.popup.hide();
|
this.popup.hide();
|
||||||
|
|
||||||
this.editor.completer.activated = false;
|
this.activated = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.changeListener = function(e) {
|
this.changeListener = function(e) {
|
||||||
if (this.editor.completer.activated)
|
if (this.activated)
|
||||||
this.complete(this.editor);
|
this.showPopup(this.editor);
|
||||||
else
|
else
|
||||||
this.detach();
|
this.detach();
|
||||||
};
|
};
|
||||||
|
|
@ -98,13 +99,11 @@ var Autocomplete = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.mousedownListener = function(e) {
|
this.mousedownListener = function(e) {
|
||||||
var mouseX = e.clientX, mouseY = e.clientY;
|
this.detach();
|
||||||
var newRow = this.editor.renderer.pixelToScreenCoordinates(mouseX, mouseY).row;
|
};
|
||||||
var currentRow = e.editor.getCursorPosition().row;
|
|
||||||
|
|
||||||
if (newRow !== currentRow) {
|
this.mousewheelListener = function(e) {
|
||||||
this.detach();
|
this.detach();
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.goTo = function(where) {
|
this.goTo = function(where) {
|
||||||
|
|
@ -126,15 +125,16 @@ var Autocomplete = function() {
|
||||||
if (!data)
|
if (!data)
|
||||||
data = this.popup.getData(this.popup.getRow());
|
data = this.popup.getData(this.popup.getRow());
|
||||||
if (!data)
|
if (!data)
|
||||||
return false;
|
return false;
|
||||||
if (data.completer && data.completer.insertMatch) {
|
if (data.completer && data.completer.insertMatch) {
|
||||||
data.completer.insertMatch(this.editor);
|
data.completer.insertMatch(this.editor);
|
||||||
} else {
|
} else {
|
||||||
if (data.value)
|
if (data.value)
|
||||||
data = data.value;
|
data = data.value;
|
||||||
this.editor.removeWordLeft();
|
if (data.prefix)
|
||||||
this.editor.insert(data);
|
this.editor.removeWordLeft();
|
||||||
}
|
this.editor.insert(data);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.commands = {
|
this.commands = {
|
||||||
|
|
@ -153,7 +153,7 @@ var Autocomplete = function() {
|
||||||
"PageDown": function(editor) { editor.completer.popup.gotoPageUp(); }
|
"PageDown": function(editor) { editor.completer.popup.gotoPageUp(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getCompletions = function(editor, callback) {
|
this.gatherCompletions = function(editor, callback) {
|
||||||
var session = editor.getSession();
|
var session = editor.getSession();
|
||||||
var pos = editor.getCursorPosition();
|
var pos = editor.getCursorPosition();
|
||||||
|
|
||||||
|
|
@ -179,7 +179,7 @@ var Autocomplete = function() {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.complete = function(editor) {
|
this.showPopup = function(editor) {
|
||||||
if (this.editor)
|
if (this.editor)
|
||||||
this.detach();
|
this.detach();
|
||||||
|
|
||||||
|
|
@ -195,18 +195,18 @@ var Autocomplete = function() {
|
||||||
editor.on("blur", this.blurListener);
|
editor.on("blur", this.blurListener);
|
||||||
editor.on("mousedown", this.mousedownListener);
|
editor.on("mousedown", this.mousedownListener);
|
||||||
|
|
||||||
this.getCompletions(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)
|
if (matches.length == 1)
|
||||||
return this.insertMatch(matches[0]);
|
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(editor);
|
||||||
this.popup.setHighlight(results.prefix);
|
this.popup.setHighlight(results.prefix);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cancelContextMenu = function() {
|
this.cancelContextMenu = function() {
|
||||||
|
|
@ -219,8 +219,6 @@ var Autocomplete = function() {
|
||||||
this.editor.on("nativecontextmenu", stop);
|
this.editor.on("nativecontextmenu", stop);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.completers = [];
|
|
||||||
|
|
||||||
}).call(Autocomplete.prototype);
|
}).call(Autocomplete.prototype);
|
||||||
|
|
||||||
Autocomplete.startCommand = {
|
Autocomplete.startCommand = {
|
||||||
|
|
@ -228,8 +226,7 @@ Autocomplete.startCommand = {
|
||||||
exec: function(editor) {
|
exec: function(editor) {
|
||||||
if (!editor.completer)
|
if (!editor.completer)
|
||||||
editor.completer = new Autocomplete();
|
editor.completer = new Autocomplete();
|
||||||
editor.completer.complete(editor);
|
editor.completer.showPopup(editor);
|
||||||
editor.completer.activated = true;
|
|
||||||
// needed for firefox on mac
|
// needed for firefox on mac
|
||||||
editor.completer.cancelContextMenu();
|
editor.completer.cancelContextMenu();
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue