mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
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:
parent
dbdbfb0322
commit
19fd1196f8
5 changed files with 51 additions and 10 deletions
|
@ -254,6 +254,10 @@ const DEFAULTS = o({
|
|||
"curl -fsSl https://raw.githubusercontent.com/cmcaine/tridactyl/master/native/install.sh | bash",
|
||||
profiledir: "auto",
|
||||
|
||||
// Container settings
|
||||
// If enabled, tabopen opens a new tab in the currently active tab's container.
|
||||
tabopencontaineraware: "false",
|
||||
|
||||
// Performance related settings
|
||||
|
||||
// number of most recent results to ask Firefox for. We display the top 20 or so most frequently visited ones.
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
|
||||
// Shared
|
||||
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 * as UrlUtil from "./url_util"
|
||||
import * as config from "./config"
|
||||
|
@ -1244,7 +1244,10 @@ export async function tabopen(...addressarr: string[]) {
|
|||
} else if (address != "") url = forceURI(address)
|
||||
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.
|
||||
|
|
|
@ -537,7 +537,7 @@ const HINTTAGS_saveable = `
|
|||
[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. */
|
||||
function simulateClick(target: HTMLElement) {
|
||||
|
@ -550,7 +550,18 @@ function simulateClick(target: HTMLElement) {
|
|||
(target as HTMLAnchorElement).target === "_blank" ||
|
||||
(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 {
|
||||
DOM.mouseEvent(target, "click")
|
||||
// DOM.focus has additional logic for focusing inputs
|
||||
|
@ -563,10 +574,21 @@ function hintPageOpenInBackground(selectors = HINTTAGS_selectors) {
|
|||
hint.target.focus()
|
||||
if (hint.target.href) {
|
||||
// Try to open with the webext API. If that fails, simulate a click on this page anyway.
|
||||
// Try to open the new tab in the same container as the current one.
|
||||
activeTabContainerId().then(containerId => {
|
||||
if (containerId) {
|
||||
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 {
|
||||
// This is to mirror vimperator behaviour.
|
||||
simulateClick(hint.target)
|
||||
|
|
|
@ -67,6 +67,11 @@ export async function activeTabId() {
|
|||
return (await activeTab()).id
|
||||
}
|
||||
|
||||
//#background_helper
|
||||
export async function activeTabContainerId() {
|
||||
return (await activeTab()).cookieStoreId
|
||||
}
|
||||
|
||||
/** Compare major firefox versions */
|
||||
export async function firefoxVersionAtLeast(desiredmajor: number) {
|
||||
const versionstr = (await browserBg.runtime.getBrowserInfo()).version
|
||||
|
@ -88,12 +93,17 @@ export async function firefoxVersionAtLeast(desiredmajor: number) {
|
|||
*/
|
||||
export async function openInNewTab(
|
||||
url: string,
|
||||
kwargs: { active?; related? } = { active: true, related: false },
|
||||
kwargs: { active?; related?; cookieStoreId? } = {
|
||||
active: true,
|
||||
related: false,
|
||||
cookieStoreId: undefined,
|
||||
},
|
||||
) {
|
||||
const thisTab = await activeTab()
|
||||
const options: any = {
|
||||
active: kwargs.active,
|
||||
url,
|
||||
cookieStoreId: kwargs.cookieStoreId,
|
||||
}
|
||||
|
||||
// Be nice to behrmann, #342
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
"bookmarks",
|
||||
"browsingData",
|
||||
"contextMenus",
|
||||
"contextualIdentities",
|
||||
"cookies",
|
||||
"clipboardWrite",
|
||||
"clipboardRead",
|
||||
"downloads",
|
||||
|
|
Loading…
Add table
Reference in a new issue