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; 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,13 +153,13 @@ 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();
var line = session.getLine(pos.row); var line = session.getLine(pos.row);
var prefix = util.retrievePrecedingIdentifier(line, pos.column); var prefix = util.retrievePrecedingIdentifier(line, pos.column);
var matches = []; var matches = [];
util.parForEach(editor.completers, function(completer, next) { util.parForEach(editor.completers, function(completer, next) {
completer.getCompletions(session, pos, prefix, function(err, results) { completer.getCompletions(session, pos, prefix, function(err, results) {
@ -178,8 +178,8 @@ 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,20 +195,20 @@ 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() {
var stop = function(e) { var stop = function(e) {
this.editor.off("nativecontextmenu", stop); this.editor.off("nativecontextmenu", stop);
@ -218,8 +218,6 @@ var Autocomplete = function() {
setTimeout(stop, 10); setTimeout(stop, 10);
this.editor.on("nativecontextmenu", stop); this.editor.on("nativecontextmenu", stop);
}; };
this.completers = [];
}).call(Autocomplete.prototype); }).call(Autocomplete.prototype);
@ -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();
}, },