Set tree node selected after close an editor

This commit is contained in:
Liang Ding 2015-12-04 15:28:29 +08:00
parent 10de6cd3d9
commit 8f4fc25324
2 changed files with 34 additions and 42 deletions

View File

@ -130,28 +130,9 @@ var editors = {
wide.curEditor = undefined; wide.curEditor = undefined;
$(".footer .cursor").text(''); $(".footer .cursor").text('');
wide.refreshOutline(); wide.refreshOutline();
return false; return false;
} }
// set tree node selected
var tId = tree.getTIdByPath(id);
var node = tree.fileTree.getNodeByTId(tId);
tree.fileTree.selectNode(node);
wide.curNode = node;
for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (editors.data[i].id === id) {
wide.curEditor = editors.data[i].editor;
break;
}
}
var cursor = wide.curEditor.getCursor();
wide.curEditor.setCursor(cursor);
wide.curEditor.focus();
wide.refreshOutline();
$(".footer .cursor").text('| ' + (cursor.line + 1) + ':' + (cursor.ch + 1) + ' |');
}, },
removeBefore: function (id) { removeBefore: function (id) {
if (id === 'startPage') { // 当前关闭的 tab 是起始页 if (id === 'startPage') { // 当前关闭的 tab 是起始页
@ -219,23 +200,6 @@ var editors = {
// 关闭的不是当前编辑器 // 关闭的不是当前编辑器
return false; return false;
} }
// set tree node selected
var tId = tree.getTIdByPath(id);
var node = tree.fileTree.getNodeByTId(tId);
tree.fileTree.selectNode(node);
wide.curNode = node;
for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (editors.data[i].id === nextId) {
wide.curEditor = editors.data[i].editor;
break;
}
}
wide.refreshOutline();
var cursor = wide.curEditor.getCursor();
$(".footer .cursor").text('| ' + (cursor.line + 1) + ':' + (cursor.ch + 1) + ' |');
} }
}); });
@ -320,11 +284,12 @@ var editors = {
}); });
}, },
getCurrentId: function () { getCurrentId: function () {
var currentId = editors.tabs.getCurrentId(); var ret = editors.tabs.getCurrentId();
if (currentId === 'startPage') { if (ret === 'startPage') {
currentId = null; ret = null;
} }
return currentId;
return ret;
}, },
getCurrentPath: function () { getCurrentPath: function () {
var currentPath = $(".edit-panel .tabs .current span:eq(0)").attr("title"); var currentPath = $(".edit-panel .tabs .current span:eq(0)").attr("title");

View File

@ -46,7 +46,7 @@ $.extend(Tabs.prototype, {
if ($(this).hasClass('current')) { if ($(this).hasClass('current')) {
return false; return false;
} }
var id = $(this).data("index"); var id = $(this).data("index");
_that.setCurrent(id); _that.setCurrent(id);
if (typeof (obj.clickAfter) === "function") { if (typeof (obj.clickAfter) === "function") {
@ -161,5 +161,32 @@ $.extend(Tabs.prototype, {
if (typeof this.obj.setAfter === 'function') { if (typeof this.obj.setAfter === 'function') {
this.obj.setAfter(); this.obj.setAfter();
} }
var id = this.getCurrentId();
if ("startPage" === id) {
return;
}
// set tree node selected
var tId = tree.getTIdByPath(id);
var node = tree.fileTree.getNodeByTId(tId);
tree.fileTree.selectNode(node);
wide.curNode = node;
for (var i = 0, ii = editors.data.length; i < ii; i++) {
if (editors.data[i].id === id) {
wide.curEditor = editors.data[i].editor;
break;
}
}
if (wide.curEditor) {
var cursor = wide.curEditor.getCursor();
wide.curEditor.setCursor(cursor);
wide.curEditor.focus();
wide.refreshOutline();
$(".footer .cursor").text('| ' + (cursor.line + 1) + ':' + (cursor.ch + 1) + ' |');
}
} }
}); });