Skip to content
This repository has been archived by the owner on Mar 5, 2019. It is now read-only.

Tab stacking #29

Open
Kamui-Solo opened this issue May 27, 2015 · 3 comments
Open

Tab stacking #29

Kamui-Solo opened this issue May 27, 2015 · 3 comments

Comments

@Kamui-Solo
Copy link

This code from tabutils.js is responsible for tab stacking:

  //在当前标签页的右侧打开新标签页
  //连续打开后台标签时保持原有顺序
  TU_hookCode("gBrowser.addTab",
    [/\S*insertRelatedAfterCurrent\S*(?=\))/, "false"],
    [/(?=(return t;)(?![\s\S]*\1))/, function() {
      if (t.hasAttribute("opener")) {
        function shouldStack(tab) { let args = tab.arguments; return args.aReferrerURI || args.aRelatedToCurrent && args.aURI != "about:blank"; }

        let lastRelatedTab = this.mCurrentTab;
        let isStack = this.isStackedTab(lastRelatedTab);
        let willStack = (isStack || TU_getPref("extensions.tabutils.autoStack", false)) && shouldStack(t);
        if (isStack && !willStack)
          lastRelatedTab = this.lastSiblingTabOf(lastRelatedTab);

        if (TU_getPref("extensions.tabutils.openTabNext.keepOrder", true)) {
          let tab = lastRelatedTab.nextSibling;
          let panelId = this.mCurrentTab.linkedPanel + "#";
          for (; tab && tab.pinned; tab = tab.nextSibling);
          for (; tab && tab.getAttribute("opener") == panelId && tab != t && (!willStack || shouldStack(tab)); tab = tab.nextSibling)
            lastRelatedTab = tab;
        }

        if (willStack)
          this.attachTabTo(t, lastRelatedTab, {move: true, expand: true});
        this.moveTabTo(t, t._tPos > lastRelatedTab._tPos ? lastRelatedTab._tPos + 1 : lastRelatedTab._tPos);
      }
    }]
  );

  TU_hookCode("gBrowser.onTabOpen", "}", function() {
    if ((function() {
      switch (TU_getPref("extensions.tabutils.openTabNext", 1)) {
        case 1: //All
        case 2: return aRelatedToCurrent || aReferrerURI || aURI != "about:blank"; //All but New Tab
        case 3: return aRelatedToCurrent == null ? aReferrerURI : aRelatedToCurrent; //None but Links
        default: return false; //None
      }
    })()) {
      aTab.setAttribute("opener", this.mCurrentTab.linkedPanel + "#");
    }
  });

  TU_hookCode("gBrowser.onTabPinned", "}", function() {
    aTab.removeAttribute("opener");
  });

  TU_hookCode("gBrowser.onTabUnstacked", "}", function() {
    aTab.removeAttribute("opener");
    if (aTab.selected)
      this.updateCurrentBrowser(true);
  });

Logic of code is simple, according to pref extensions.tabutils.openTabNext newly opened tab get attribute "opener" and according to pref tabutils.autoStack tab stacks, it works great links and new tab action, but by some reasons it won't work for "options" and "addons" tabs opened from main menu or hotkey, although attribute "opener" added to this tabs successfully.
Any ideas about this?

@yfdyh000
Copy link
Owner

Sorry for the delay. I confirmed the issue.

Hot-patching investigation way:

gBrowser.addTab.toString() in Scratchpad (chrome context)
gBrowser.addTab = _modified code_

This problem appears to be due to alert(willStack) is undefined. isStack is good. alert(shouldStack(t)) is undefined.

console.debug(t.arguments):

Object { aURI: "about:preferences", aReferrerURI: undefined, aRelatedToCurrent: undefined }

Perhaps this is a deliberate non-related tab.
We should cover its behavior in a particular way to fully realize this preference?

@Kamui-Solo
Copy link
Author

Perhaps this is a deliberate non-related tab.

Maybe, but tabs opened from bookmarks also don't stacks.
I think "addons" and "options" are included in category "none but links", and category "all" must include all type of tabs regardless where from it's opened.

By the way in some old version this tabs stacks.

@Kamui-Solo
Copy link
Author

Fix for this issue is here:
https://forum.mozilla-russia.org/viewtopic.php?pid=684697#p684697

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants