hint -b now follows current tab's container, similar tabopen behaviour now behind a new setting 'tabopencontaineraware', defaults to false.

This commit is contained in:
Anton 2018-05-08 12:27:30 +00:00
parent dbdbfb0322
commit 19fd1196f8
5 changed files with 51 additions and 10 deletions

View file

@ -254,6 +254,10 @@ const DEFAULTS = o({
"curl -fsSl https://raw.githubusercontent.com/cmcaine/tridactyl/master/native/install.sh | bash", "curl -fsSl https://raw.githubusercontent.com/cmcaine/tridactyl/master/native/install.sh | bash",
profiledir: "auto", profiledir: "auto",
// Container settings
// If enabled, tabopen opens a new tab in the currently active tab's container.
tabopencontaineraware: "false",
// Performance related settings // Performance related settings
// number of most recent results to ask Firefox for. We display the top 20 or so most frequently visited ones. // number of most recent results to ask Firefox for. We display the top 20 or so most frequently visited ones.

View file

@ -87,7 +87,7 @@
// Shared // Shared
import * as Messaging from "./messaging" import * as Messaging from "./messaging"
import { l, browserBg, activeTabId } from "./lib/webext" import { l, browserBg, activeTabId, activeTabContainerId } from "./lib/webext"
import state from "./state" import state from "./state"
import * as UrlUtil from "./url_util" import * as UrlUtil from "./url_util"
import * as config from "./config" import * as config from "./config"
@ -1244,7 +1244,10 @@ export async function tabopen(...addressarr: string[]) {
} else if (address != "") url = forceURI(address) } else if (address != "") url = forceURI(address)
else url = forceURI(config.get("newtab")) else url = forceURI(config.get("newtab"))
openInNewTab(url, { active }) activeTabContainerId().then(containerId => {
if (containerId && config.get("tabopencontaineraware") === "true") openInNewTab(url, { active: active, cookieStoreId: containerId })
else openInNewTab(url, { active })
})
} }
/** Resolve a tab index to the tab id of the corresponding tab in this window. /** Resolve a tab index to the tab id of the corresponding tab in this window.

View file

@ -537,7 +537,7 @@ const HINTTAGS_saveable = `
[href]:not([href='#']) [href]:not([href='#'])
` `
import { openInNewTab } from "./lib/webext" import { openInNewTab, activeTabContainerId } from "./lib/webext"
/** if `target === _blank` clicking the link is treated as opening a popup and is blocked. Use webext API to avoid that. */ /** if `target === _blank` clicking the link is treated as opening a popup and is blocked. Use webext API to avoid that. */
function simulateClick(target: HTMLElement) { function simulateClick(target: HTMLElement) {
@ -550,7 +550,18 @@ function simulateClick(target: HTMLElement) {
(target as HTMLAnchorElement).target === "_blank" || (target as HTMLAnchorElement).target === "_blank" ||
(target as HTMLAnchorElement).target === "_new" (target as HTMLAnchorElement).target === "_new"
) { ) {
openInNewTab((target as HTMLAnchorElement).href, { related: true }) // Try to open the new tab in the same container as the current one.
activeTabContainerId().then(containerId => {
if (containerId)
openInNewTab((target as HTMLAnchorElement).href, {
related: true,
cookieStoreId: containerId,
})
else
openInNewTab((target as HTMLAnchorElement).href, {
related: true,
})
})
} else { } else {
DOM.mouseEvent(target, "click") DOM.mouseEvent(target, "click")
// DOM.focus has additional logic for focusing inputs // DOM.focus has additional logic for focusing inputs
@ -563,10 +574,21 @@ function hintPageOpenInBackground(selectors = HINTTAGS_selectors) {
hint.target.focus() hint.target.focus()
if (hint.target.href) { if (hint.target.href) {
// Try to open with the webext API. If that fails, simulate a click on this page anyway. // Try to open with the webext API. If that fails, simulate a click on this page anyway.
openInNewTab(hint.target.href, { // Try to open the new tab in the same container as the current one.
active: false, activeTabContainerId().then(containerId => {
related: true, if (containerId) {
}).catch(() => simulateClick(hint.target)) openInNewTab(hint.target.href, {
active: false,
related: true,
cookieStoreId: containerId,
}).catch(() => simulateClick(hint.target))
} else {
openInNewTab(hint.target.href, {
active: false,
related: true,
}).catch(() => simulateClick(hint.target))
}
})
} else { } else {
// This is to mirror vimperator behaviour. // This is to mirror vimperator behaviour.
simulateClick(hint.target) simulateClick(hint.target)

View file

@ -67,6 +67,11 @@ export async function activeTabId() {
return (await activeTab()).id return (await activeTab()).id
} }
//#background_helper
export async function activeTabContainerId() {
return (await activeTab()).cookieStoreId
}
/** Compare major firefox versions */ /** Compare major firefox versions */
export async function firefoxVersionAtLeast(desiredmajor: number) { export async function firefoxVersionAtLeast(desiredmajor: number) {
const versionstr = (await browserBg.runtime.getBrowserInfo()).version const versionstr = (await browserBg.runtime.getBrowserInfo()).version
@ -88,12 +93,17 @@ export async function firefoxVersionAtLeast(desiredmajor: number) {
*/ */
export async function openInNewTab( export async function openInNewTab(
url: string, url: string,
kwargs: { active?; related? } = { active: true, related: false }, kwargs: { active?; related?; cookieStoreId? } = {
active: true,
related: false,
cookieStoreId: undefined,
},
) { ) {
const thisTab = await activeTab() const thisTab = await activeTab()
const options: any = { const options: any = {
active: kwargs.active, active: kwargs.active,
url, url,
cookieStoreId: kwargs.cookieStoreId,
} }
// Be nice to behrmann, #342 // Be nice to behrmann, #342

View file

@ -43,6 +43,8 @@
"bookmarks", "bookmarks",
"browsingData", "browsingData",
"contextMenus", "contextMenus",
"contextualIdentities",
"cookies",
"clipboardWrite", "clipboardWrite",
"clipboardRead", "clipboardRead",
"downloads", "downloads",
@ -63,4 +65,4 @@
"strict_min_version": "54.0" "strict_min_version": "54.0"
} }
} }
} }