fix gotoline after removing list

pull/125/merge
nightwing 2017-04-10 02:57:50 +00:00
rodzic 27caac758d
commit f349a97928
1 zmienionych plików z 46 dodań i 45 usunięć

Wyświetl plik

@ -71,11 +71,9 @@ define(function(require, exports, module) {
}, plugin); }, plugin);
settings.on("read", function() { settings.on("read", function() {
var lines = settings.getJson("state/gotoline") || []; lines = settings.getJson("state/gotoline") || [];
lines = lines.map(function(i) { if (!Array.isArray(lines))
return { value: i }; lines = [];
});
}, plugin); }, plugin);
settings.on("write", function() { settings.on("write", function() {
@ -105,45 +103,40 @@ define(function(require, exports, module) {
input = plugin.getElement("input"); input = plugin.getElement("input");
list = plugin.getElement("list"); list = plugin.getElement("list");
// list.setAttribute("model", model); list.$ext.textContent = "";
list.drawContents = function() {
list.addEventListener("afterchoose", function() { var ch = list.$ext.children;
if (list.selected) { for (var i = 0; i < lines.length; i++) {
execGotoLine(parseInt(list.selected.getAttribute("nr"), 10)); var el = ch[i];
if (!el) el = document.createElement("div");
el.setAttribute("index", i);
el.textContent = lines[i];
el.className = i == list.selected ? "selected" : "";
if (el.parentNode != list.$ext)
list.$ext.appendChild(el);
} }
else { while (ch.length > lines.length)
execGotoLine(); ch[lines.length].remove();
};
list.selected = -1;
list.$ext.addEventListener("mouseup", function(e) {
var i = parseInt(e.target.getAttribute("index"), 10);
if (i >= 0) {
list.selected = i;
input.setValue(lines[list.selected]);
list.drawContents();
execGotoLine(null, null, e.detail == 1);
if (e.detail != 1) hide();
} }
}); });
list.addEventListener("afterselect", function() {
if (!list.selected)
return;
var line = list.selected.getAttribute("nr"); list.$altExt.addEventListener("mousedown", function(e) {
input.setValue(line); input.focus();
e.preventDefault();
// Focus the list e.stopPropagation();
list.focus();
// Go to the right line
execGotoLine(null, null, true);
}); });
var restricted = [38, 40, 36, 35];
list.addEventListener("keydown", function(e) {
if (e.keyCode == 13 && list.selected) {
return false;
}
else if (e.keyCode == 38) {
if (list.selected == list.getFirstTraverseNode()) {
input.focus();
list.clearSelection();
}
}
else if (restricted.indexOf(e.keyCode) == -1)
input.focus();
}, true);
input.addEventListener("keydown", function(e) { input.addEventListener("keydown", function(e) {
var NotANumber = (e.keyCode > 57 || e.keyCode == 32) var NotANumber = (e.keyCode > 57 || e.keyCode == 32)
&& (e.keyCode < 96 || e.keyCode > 105); && (e.keyCode < 96 || e.keyCode > 105);
@ -153,12 +146,18 @@ define(function(require, exports, module) {
return false; return false;
} }
else if (e.keyCode == 40) { else if (e.keyCode == 40) {
var first = list.getFirstTraverseNode(); if (list.selected == -1)
if (first) { list.cache = input.getValue();
list.select(first); if (list.selected < lines.length -1)
list.$container.scrollTop = 0; list.selected++;
list.focus(); input.setValue(lines[list.selected]);
list.drawContents();
} }
else if (e.keyCode == 38) {
if (list.selected > -1)
list.selected--;
input.setValue(lines[list.selected] || list.cache);
list.drawContents();
} }
else if (NotANumber && !e.metaKey && !e.ctrlKey && !e.altKey) { else if (NotANumber && !e.metaKey && !e.ctrlKey && !e.altKey) {
return false; return false;
@ -204,6 +203,8 @@ define(function(require, exports, module) {
//Set the current line //Set the current line
input.setValue(input.getValue() || cursor.row + 1); input.setValue(input.getValue() || cursor.row + 1);
list.drawContents();
//Determine the position of the window //Determine the position of the window
var pos = ace.renderer.textToScreenCoordinates(cursor.row, cursor.column); var pos = ace.renderer.textToScreenCoordinates(cursor.row, cursor.column);
var epos = ui.getAbsolutePosition(aceHtml.parentNode); var epos = ui.getAbsolutePosition(aceHtml.parentNode);