kopia lustrzana https://github.com/c9/core
fix gotoline after removing list
rodzic
27caac758d
commit
f349a97928
|
@ -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() {
|
||||||
|
var ch = list.$ext.children;
|
||||||
|
for (var i = 0; i < lines.length; i++) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
while (ch.length > lines.length)
|
||||||
|
ch[lines.length].remove();
|
||||||
|
};
|
||||||
|
list.selected = -1;
|
||||||
|
|
||||||
list.addEventListener("afterchoose", function() {
|
list.$ext.addEventListener("mouseup", function(e) {
|
||||||
if (list.selected) {
|
var i = parseInt(e.target.getAttribute("index"), 10);
|
||||||
execGotoLine(parseInt(list.selected.getAttribute("nr"), 10));
|
if (i >= 0) {
|
||||||
}
|
list.selected = i;
|
||||||
else {
|
input.setValue(lines[list.selected]);
|
||||||
execGotoLine();
|
list.drawContents();
|
||||||
|
execGotoLine(null, null, e.detail == 1);
|
||||||
|
if (e.detail != 1) hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
list.addEventListener("afterselect", function() {
|
|
||||||
if (!list.selected)
|
list.$altExt.addEventListener("mousedown", function(e) {
|
||||||
return;
|
input.focus();
|
||||||
|
e.preventDefault();
|
||||||
var line = list.selected.getAttribute("nr");
|
e.stopPropagation();
|
||||||
input.setValue(line);
|
|
||||||
|
|
||||||
// Focus the list
|
|
||||||
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;
|
||||||
|
@ -203,6 +202,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);
|
||||||
|
|
Ładowanie…
Reference in New Issue