bpierre/gtranslate

Open the new tab next to the current one

bpierre opened this issue · 7 comments

The new tab should open just on the right on the current tab, not at the end of the tabs bar.

The tabs.open() method opens a tab at the end of the tabs bar by default.

  • There is no option to do it in tabs.open()
  • The inBackground option does the same, despite its description: “If present and true, the new tab will be opened to the right of the active tab and will not be active.”
  • Changing the tab position after opening it does not work: the move is visible to the user.

Some information here: https://bugzilla.mozilla.org/show_bug.cgi?id=715560

Need to investigate to find a solid solution.

Hi @bpierre

I tried to fix it but the inBackground option doesn't seem to open the tab at right of the active tab (as said in the documentation. Otherwise, a hack could be something like this:

    // Open the translation page
    if (target === result) {
      tabs.open({
        url: translateUrl(currentFrom().code, currentTo().code, selection),
        inBackground: true,
        onOpen: function onOpen(tab) {
          tab.activate();
        }
      });
      return
    }

Yes that’s what I tried first, but sadly the inBackground behaviour does not match with the documentation…

Another solution would be to manually change the position, but the tab jump is visible when using the onOpen callback.

z87 commented

Is the callback necessary though? This works for me without any noticeable effects:

const index = tabs.activeTab.index + 1
tabs.open(translateUrl(currentFrom(languages).code, currentTo(languages).code, selection))
tabs.activeTab.index = index

@z87 Have you tried with and without E10S?

z87 commented

@bpierre Turns out it doesn't work with e10s at all. Sorry!

This should work just fine:

    // Open the translation page
    if (target === result) {
      let url = translateUrl(currentFrom(languages).code, currentTo(languages).code, selection)
      win.gBrowser.loadOneTab(url, {relatedToCurrent: true})
      return
    }

Note: The pref "browser.tabs.insertRelatedAfterCurrent" must be true. (this pref is true by default)

Can you also add an option to make the tab active by default?
Like so:

    // Open the translation page
    if (target === result) {
      let url = translateUrl(currentFrom(languages).code, currentTo(languages).code, selection)
      win.gBrowser.loadOneTab(url, {relatedToCurrent: true, inBackground: option ? true : false})
      return
    }

Note: option is the pref. (gtranslate load in background setting)

Thanks all!