From fe1fdbf01484e16ad1b8579730f3b630c88a1fc1 Mon Sep 17 00:00:00 2001 From: piro Date: Mon, 16 Mar 2009 14:04:29 +0000 Subject: [PATCH] =?UTF-8?q?cleanUpTabsArray=E3=81=AE=E5=AE=9F=E8=A3=85?= =?UTF-8?q?=E3=82=92=E6=94=B9=E5=96=84?= 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@3814 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/treestyletab.js | 21 ++++++++------------- tests/unit/treestyletab_tabUtils.test.js | 13 +++++++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index 20152cfa..583f1c27 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -1778,19 +1778,14 @@ catch(e) { cleanUpTabsArray : function(aTabs) { - var b = this.getTabBrowserFromChild(aTabs[0]); - - aTabs = aTabs.map(function(aTab) { - return aTab.getAttribute(this.kID); - }, this); - aTabs.sort(); - aTabs = aTabs.join('|').replace(/([^\|]+)(\|\1)+/g, '$1').split('|'); - - for (var i = 0, maxi = aTabs.length; i < maxi; i++) - { - aTabs[i] = b.treeStyleTab.getTabById(aTabs[i]); - } - return aTabs; + var newTabs = []; + aTabs.forEach(function(aTab) { + if (newTabs.indexOf(aTab) < 0) newTabs.push(aTab); + }); + newTabs.sort(function(aA, aB) { + return aA._tPos - aB._tPos; + }); + return newTabs; }, bookmarkTabSubTree : function(aTabOrTabs) diff --git a/tests/unit/treestyletab_tabUtils.test.js b/tests/unit/treestyletab_tabUtils.test.js index 5d8cf88f..d327b3a3 100644 --- a/tests/unit/treestyletab_tabUtils.test.js +++ b/tests/unit/treestyletab_tabUtils.test.js @@ -226,12 +226,17 @@ function test_setAndGetTabValue() assertSetAndGetTabValue(tabs[2], 'tab2'); } +function test_cleanUpTabsArray() +{ + var array = [0, 1, 2, 1, 3, 0] + .map(function(aIndex) { + return tabs[aIndex] + }); + assert.equals(tabs, Array.slice(sv.cleanUpTabsArray(array))); +} + /* - -sv.cleanUpTabsArray(tabs) - - sv.registerAttachTabPostProcess(func) sv.registerTabFocusAllowance(func)