現在のタブを閉じた時に、予想だにしない位置のタブにフォーカスが飛んでしまうことがあったのを修正

http://piro.sakura.ne.jp/cgi-bin/bbs.cgi?2577
(親タブを閉じた後に子タブが親の階層に組み込まれた時、内部的なタブの並び順が実際の並び順と異なる状態になってしまうことがあったのを修正)

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5590 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2009-12-22 08:05:16 +00:00
parent 8adf4b6178
commit e81324719b
2 changed files with 37 additions and 27 deletions

View File

@ -977,7 +977,7 @@ var TreeStyleTabService = {
var parentTab = this.getParentTab(aTab); var parentTab = this.getParentTab(aTab);
if (!parentTab) { if (!parentTab) {
var next = aTab; let next = aTab;
do { do {
next = next.nextSibling; next = next.nextSibling;
} }
@ -989,10 +989,10 @@ var TreeStyleTabService = {
var children = parentTab.getAttribute(this.kCHILDREN); var children = parentTab.getAttribute(this.kCHILDREN);
if (children) { if (children) {
var list = ('|'+children).split('|'+aTab.getAttribute(this.kID))[1].split('|'); let list = ('|'+children).split('|'+aTab.getAttribute(this.kID))[1].split('|');
for (var i = 0, maxi = list.length; i < maxi; i++) for (let i = 0, maxi = list.length; i < maxi; i++)
{ {
var firstChild = this.getTabById(list[i], aTab); let firstChild = this.getTabById(list[i], aTab);
if (firstChild) return firstChild; if (firstChild) return firstChild;
} }
} }
@ -1006,7 +1006,7 @@ var TreeStyleTabService = {
var parentTab = this.getParentTab(aTab); var parentTab = this.getParentTab(aTab);
if (!parentTab) { if (!parentTab) {
var prev = aTab; let prev = aTab;
do { do {
prev = prev.previousSibling; prev = prev.previousSibling;
} }
@ -1018,10 +1018,10 @@ var TreeStyleTabService = {
var children = parentTab.getAttribute(this.kCHILDREN); var children = parentTab.getAttribute(this.kCHILDREN);
if (children) { if (children) {
var list = ('|'+children).split('|'+aTab.getAttribute(this.kID))[0].split('|'); let list = ('|'+children).split('|'+aTab.getAttribute(this.kID))[0].split('|');
for (var i = list.length-1; i > -1; i--) for (let i = list.length-1; i > -1; i--)
{ {
var lastChild = this.getTabById(list[i], aTab); let lastChild = this.getTabById(list[i], aTab);
if (lastChild) return lastChild; if (lastChild) return lastChild;
} }
} }
@ -1039,10 +1039,9 @@ var TreeStyleTabService = {
if (aAllTabsArray) tabs = aAllTabsArray; if (aAllTabsArray) tabs = aAllTabsArray;
var list = children.split('|'); var list = children.split('|');
var tab; for (let i = 0, maxi = list.length; i < maxi; i++)
for (var i = 0, maxi = list.length; i < maxi; i++)
{ {
tab = this.getTabById(list[i], aTab); let tab = this.getTabById(list[i], aTab);
if (!tab) continue; if (!tab) continue;
tabs.push(tab); tabs.push(tab);
if (aAllTabsArray) if (aAllTabsArray)
@ -1072,8 +1071,8 @@ var TreeStyleTabService = {
var children = aTab.getAttribute(this.kCHILDREN); var children = aTab.getAttribute(this.kCHILDREN);
var firstChild = null; var firstChild = null;
if (children) { if (children) {
var list = children.split('|'); let list = children.split('|');
for (var i = 0, maxi = list.length; i < maxi; i++) for (let i = 0, maxi = list.length; i < maxi; i++)
{ {
firstChild = this.getTabById(list[i], aTab); firstChild = this.getTabById(list[i], aTab);
if (firstChild) break; if (firstChild) break;
@ -1089,8 +1088,8 @@ var TreeStyleTabService = {
var children = aTab.getAttribute(this.kCHILDREN); var children = aTab.getAttribute(this.kCHILDREN);
var lastChild = null; var lastChild = null;
if (children) { if (children) {
var list = children.split('|'); let list = children.split('|');
for (var i = list.length-1; i > -1; i--) for (let i = list.length-1; i > -1; i--)
{ {
lastChild = this.getTabById(list[i], aTab); lastChild = this.getTabById(list[i], aTab);
if (lastChild) break; if (lastChild) break;
@ -1123,18 +1122,18 @@ var TreeStyleTabService = {
} }
if (aParent) { if (aParent) {
var children = aParent.getAttribute(this.kCHILDREN); let children = aParent.getAttribute(this.kCHILDREN);
var list = children.split('|'); let list = children.split('|');
var id = aTab.getAttribute(this.kID); let id = aTab.getAttribute(this.kID);
for (var i = 0, maxi = list.length; i < maxi; i++) for (let i = 0, maxi = list.length; i < maxi; i++)
{ {
if (list[i] == id) return i; if (list[i] == id) return i;
} }
return -1; return -1;
} }
else { else {
var tabs = this.rootTabs; let tabs = this.rootTabs;
for (var i = 0, maxi = tabs.length; i < maxi; i++) for (let i = 0, maxi = tabs.length; i < maxi; i++)
{ {
if (tabs[i] == aTab) return i; if (tabs[i] == aTab) return i;
} }
@ -1186,7 +1185,7 @@ var TreeStyleTabService = {
} }
if (this.useTMPSessionAPI) { if (this.useTMPSessionAPI) {
var TMPValue = aTab.getAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey); let TMPValue = aTab.getAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey);
if (TMPValue) value = TMPValue; if (TMPValue) value = TMPValue;
} }
@ -2552,12 +2551,15 @@ catch(e) {
if (!aTab.parentNode) return; // ignore removed tabs if (!aTab.parentNode) return; // ignore removed tabs
if (newTabs.indexOf(aTab) < 0) newTabs.push(aTab); if (newTabs.indexOf(aTab) < 0) newTabs.push(aTab);
}); });
newTabs.sort(function(aA, aB) { newTabs.sort(this.sortTabsByOrder);
return aA._tPos - aB._tPos;
});
return newTabs; return newTabs;
}, },
sortTabsByOrder : function(aA, aB)
{
return aA._tPos - aB._tPos;
},
reloadTabSubTree : function(aTabOrTabs, aOnlyChildren) reloadTabSubTree : function(aTabOrTabs, aOnlyChildren)
{ {
var tabs = this._normalizeToTabs(aTabOrTabs, aOnlyChildren); var tabs = this._normalizeToTabs(aTabOrTabs, aOnlyChildren);

View File

@ -1831,7 +1831,7 @@ TreeStyleTabBrowser.prototype = {
updateChildrenArray : function(aTab) updateChildrenArray : function(aTab)
{ {
var children = this.getChildTabs(aTab); var children = this.getChildTabs(aTab);
children.sort(function(aA, aB) { return aA._tPos - aB._tPos; }); children.sort(this.sortTabsByOrder);
this.setTabValue( this.setTabValue(
aTab, aTab,
this.kCHILDREN, this.kCHILDREN,
@ -2985,6 +2985,14 @@ TreeStyleTabBrowser.prototype = {
} }
else { else {
children.push(id); children.push(id);
if (aInfo.dontMove && children.length > 1) {
children = children
.map(this.getTabById, this)
.sort(this.sortTabsByOrder)
.map(function(aTab) {
return aTab.getAttribute(this.kID);
}, this);
}
let refTab = aParent; let refTab = aParent;
let descendant = this.getDescendantTabs(aParent); let descendant = this.getDescendantTabs(aParent);
if (descendant.length) refTab = descendant[descendant.length-1]; if (descendant.length) refTab = descendant[descendant.length-1];