hide the popup when editor is scrolled

This commit is contained in:
nightwing 2013-06-09 00:24:20 +04:00
commit 35a9dc5ba1

View file

@ -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;
var newRow = this.editor.renderer.pixelToScreenCoordinates(mouseX, mouseY).row;
var currentRow = e.editor.getCursorPosition().row;
if (newRow !== currentRow) {
this.detach(); this.detach();
} };
this.mousewheelListener = function(e) {
this.detach();
}; };
this.goTo = function(where) { this.goTo = function(where) {
@ -132,6 +131,7 @@ var Autocomplete = function() {
} else { } else {
if (data.value) if (data.value)
data = data.value; data = data.value;
if (data.prefix)
this.editor.removeWordLeft(); this.editor.removeWordLeft();
this.editor.insert(data); this.editor.insert(data);
} }
@ -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,7 +195,7 @@ 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();
@ -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();
}, },