From c44fa859dc53c5a3d4442172fd7f7dbc9451ea47 Mon Sep 17 00:00:00 2001 From: YUKI Hiroshi Date: Thu, 7 Jul 2016 18:39:42 +0900 Subject: [PATCH] Open new tab next to the current tab correctly, even if the current tab is the last tab --- modules/base.js | 25 +++++++++++++++++++------ modules/browser.js | 6 ++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/modules/base.js b/modules/base.js index 63d8541f..c6af8e29 100644 --- a/modules/base.js +++ b/modules/base.js @@ -1307,11 +1307,14 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { /* notify "ready to open child tab(s)" */ - readyToOpenChildTab : function TSTBase_readyToOpenChildTab(aTabOrSomething, aMultiple, aInsertBefore) /* PUBLIC API */ + readyToOpenChildTab : function TSTBase_readyToOpenChildTab(aTabOrSomething, aMultiple, aOptions) /* PUBLIC API */ { if (!utils.getTreePref('autoAttach')) return false; + if (aOptions instanceof Ci.nsIDOMElement) // for backward compatibility + aOptions = { insertBefore : aOptions }; + var browser = this.getBrowserFromTabBrowserElements(aTabOrSomething); if (!browser) return false; @@ -1325,10 +1328,15 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { ownerBrowser.treeStyleTab.ensureTabInitialized(parentTab); var parentId = parentTab.getAttribute(this.kID); - var refId = null; - if (aInsertBefore) { + var insertBefore = null; + if (aOptions.insertBefore) { ownerBrowser.treeStyleTab.ensureTabInitialized(parentTab); - refId = aInsertBefore.getAttribute(this.kID); + insertBefore = aOptions.insertBefore.getAttribute(this.kID); + } + var insertAfter = null; + if (aOptions.insertAfter) { + ownerBrowser.treeStyleTab.ensureTabInitialized(parentTab); + insertAfter = aOptions.insertAfter.getAttribute(this.kID); } logWithStackTrace('new child tab is requested.'); @@ -1337,7 +1345,8 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { ownerBrowser.treeStyleTab.readiedToAttachMultiple = aMultiple || false ; ownerBrowser.treeStyleTab.multipleCount = aMultiple ? 0 : -1 ; ownerBrowser.treeStyleTab.parentTab = parentId; - ownerBrowser.treeStyleTab.insertBefore = refId; + ownerBrowser.treeStyleTab.insertBefore = insertBefore; + ownerBrowser.treeStyleTab.insertAfter = insertAfter; return true; }, @@ -1411,12 +1420,16 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { var parentTab = this.getParentTab(tab); var nextTab = this.getNextSiblingTab(tab) || this.getNextTab(tab); + var previousTab = this.getPreviousTab(tab); if (parentTab) { /** * If the base tab has a parent, open the new tab as a child of * the parent tab. */ - return this.readyToOpenChildTab(parentTab, false, nextTab); + return this.readyToOpenChildTab(parentTab, false, { + insertBefore : nextTab, + insertAfter : previousTab + }); } else { /** diff --git a/modules/browser.js b/modules/browser.js index 5b99065a..df074b47 100644 --- a/modules/browser.js +++ b/modules/browser.js @@ -3244,6 +3244,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, { 'readiedToAttachNewTab: '+this.readiedToAttachNewTab, 'parentTab: '+this.parentTab + ' (' + this.getTabById(this.parentTab) + ')', 'insertBefore: '+this.insertBefore, + 'insertAfter: '+this.insertAfter, 'treeStructure: '+this.treeStructure ].join('\n ')); @@ -3287,6 +3288,11 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, { newIndex = refTab._tPos; log(' newIndex => '+newIndex+' (from "insertBefore")'); } + else if (this.insertAfter && + (refTab = this.getTabById(this.insertAfter))) { + newIndex = refTab._tPos + 1; + log(' newIndex => '+newIndex+' (from "insertAfter")'); + } else if ( parent && utils.getTreePref('insertNewChildAt') == this.kINSERT_FISRT &&