From 259f5ae3091de0491f6ab7cfd96875f1f9c171df Mon Sep 17 00:00:00 2001 From: piro Date: Sun, 20 Dec 2009 18:46:51 +0000 Subject: [PATCH] =?UTF-8?q?=E8=A4=87=E6=95=B0=E3=81=AE=E3=83=84=E3=83=AA?= =?UTF-8?q?=E3=83=BC=E3=81=AE=E5=90=8C=E6=99=82=E7=94=9F=E6=88=90=E3=82=92?= =?UTF-8?q?=E5=89=8D=E6=8F=90=E3=81=A8=E3=81=97=E3=81=9F=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5566 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/bookmarksOverlay.js | 21 +++++++++++++++++++-- content/treestyletab/treestyletabbrowser.js | 8 ++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/content/treestyletab/bookmarksOverlay.js b/content/treestyletab/bookmarksOverlay.js index 4178687a..03b803df 100644 --- a/content/treestyletab/bookmarksOverlay.js +++ b/content/treestyletab/bookmarksOverlay.js @@ -90,9 +90,17 @@ var TreeStyleTabBookmarksService = { getTreeStructureFromItems : function(aIDs) { + /* this returns... + [A] => -1 (parent is not in this tree) + [B] => 0 (parent is 1st item in this tree) + [C] => 0 (parent is 1st item in this tree) + [D] => 2 (parent is 2nd in this tree) + [E] => -1 (parent is not in this tree, and this creates another tree) + [F] => 0 (parent is 1st item in this another tree) + */ var treeStructure = aIDs.map(function(aId, aIndex) { let id = this.getParentItem(aId); - let index = id < 0 ? -1 : aIDs.indexOf(id); + let index = aIDs.indexOf(id); return index < aIndex ? index : -1 ; }, this); @@ -116,8 +124,17 @@ var TreeStyleTabBookmarksService = { }); treeStructure = treeStructure.reverse(); - treeStructure = treeStructure.map(function(aPosition, aIndex) { + var offset = 0; + treeStructure = treeStructure + .map(function(aPosition, aIndex) { return (aPosition == aIndex) ? -1 : aPosition ; + }) + .map(function(aPosition, aIndex) { + if (aPosition == -1) { + offset = aIndex; + return aPosition; + } + return aPosition - offset; }); return treeStructure; }, diff --git a/content/treestyletab/treestyletabbrowser.js b/content/treestyletab/treestyletabbrowser.js index fe360f10..75ea9a39 100644 --- a/content/treestyletab/treestyletabbrowser.js +++ b/content/treestyletab/treestyletabbrowser.js @@ -1400,13 +1400,17 @@ TreeStyleTabBrowser.prototype = { this.initTab(tab); var hasStructure = this.treeStructure && this.treeStructure.length; - var positionInTree = hasStructure ? this.treeStructure.shift() : -1 ; + var pareintIndexInTree = hasStructure ? this.treeStructure.shift() : 0 ; if (this.readiedToAttachNewTab) { + if (pareintIndexInTree < 0) { // there is no parent, so this is a new parent! + this.parentTab = tab.getAttribute(this.kID); + } + let parent = this.getTabById(this.parentTab); if (parent) { let tabs = [parent].concat(this.getDescendantTabs(parent)); - parent = (positionInTree > -1 && positionInTree < tabs.length) ? tabs[positionInTree] : parent ; + parent = pareintIndexInTree < tabs.length ? tabs[pareintIndexInTree] : parent ; } if (parent) { this.attachTabTo(tab, parent);