From c77bf89d0c4f4b786bd004e2e405d09155a3a790 Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Wed, 22 Mar 2023 14:37:09 +0100 Subject: [PATCH 1/3] Add sidebartoggle for --mode=browser binds #4640 --- src/background/user_actions.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/background/user_actions.ts b/src/background/user_actions.ts index 9cd7defa..c1bf6b56 100644 --- a/src/background/user_actions.ts +++ b/src/background/user_actions.ts @@ -36,6 +36,14 @@ function escapehatch() { })() } +/** + * Toggle the sidebar. Bind with e.g. `:bind --mode=browser sidebartoggle` + */ +function sidebartoggle() { + return browser.sidebarAction.toggle() +} + export const useractions: Record void> = { escapehatch, + sidebartoggle, } From 09172391a58344e310a2d5fd5accc07ed441fbbe Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Wed, 22 Mar 2023 14:43:17 +0100 Subject: [PATCH 2/3] Add jsua for --mode=browser binds Works like jsb but preserves the 'user action' so it can be used to open/close the sidebar, open downloaded files etc. Example usage: `:bind --mode=browser jsua browser.sidebarAction.close()` --- src/background/commands.ts | 14 ++++++++------ src/background/user_actions.ts | 7 ++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/background/commands.ts b/src/background/commands.ts index f9c3b466..b688d7be 100644 --- a/src/background/commands.ts +++ b/src/background/commands.ts @@ -6,12 +6,14 @@ import * as controller from "@src/lib/controller" function makelistener(commands: Array) { return (command_name: string) => { const command = commands.filter(c => c.name == command_name)[0] - const exstring = config.get( - "browsermaps", - keyseq.mozMapToMinimalKey(command.shortcut).toMapstr(), - ) - if (exstring in useractions) return useractions[exstring]() - return controller.acceptExCmd(exstring) + const [excmd, ...exargs] = config + .get( + "browsermaps", + keyseq.mozMapToMinimalKey(command.shortcut).toMapstr(), + ) + .split(" ") + if (excmd in useractions) return useractions[excmd](...exargs) + return controller.acceptExCmd([excmd, ...exargs].join(" ")) } } diff --git a/src/background/user_actions.ts b/src/background/user_actions.ts index c1bf6b56..fbd0c2f9 100644 --- a/src/background/user_actions.ts +++ b/src/background/user_actions.ts @@ -43,7 +43,12 @@ function sidebartoggle() { return browser.sidebarAction.toggle() } -export const useractions: Record void> = { +function jsua(...args: string[]) { + return eval(args.join(" ")) +} + +export const useractions: Record void> = { escapehatch, sidebartoggle, + jsua, } From 03f344a2e88f8a6bc992d2fd943b2aebbd11b67f Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Wed, 22 Mar 2023 15:09:58 +0100 Subject: [PATCH 3/3] Add :sidebaropen and docs for jsua/sidebartoggle --- src/excmds.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/excmds.ts b/src/excmds.ts index 75bd4761..31880748 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -3287,6 +3287,40 @@ export async function qall() { // }}} +/** + * EXPERIMENTAL: like [[open]] but loads queries in the sidebar. Doesn't actually open the sidebar - see [[sidebartoggle]]. + * + * Not all schemas are supported, such as `about:*` and Firefox's built-in search engines. Tridactyl's searchurls and jsurls work fine - `:set searchengine google` will be sufficient for most users. + * + * If you try to open the command line in the sidebar things will break. + */ +//#background +export async function sidebaropen(...urllike: string[]) { + const url = await queryAndURLwrangler(urllike) + if (typeof url === "string") return browser.sidebarAction.setPanel({panel: url}) + throw new Error("Unsupported URL for sidebar. If it was a search term try `:set searchengine google` first") +} + +/** + * Like [[jsb]] but preserves "user action" intent for use with certain web extension APIs. Can only be called with browser mode binds, e.g. + * + * `:bind --mode=browser jsua browser.sidebarAction.open(); tri.excmds.sidebaropen("https://mail.google.com/mail/mu")` + */ +//#background +export async function jsua(){ + throw new Error(":jsua can only be called through `bind --mode=browser` binds, see `:help jsua`") +} + +/** + * Toggle the side bar. Can only be called through browser mode binds, e.g. + * + * `:bind --mode=browser sidebartoggle` + */ +//#background +export async function sidebartoggle(){ + throw new Error(":sidebartoggle can only be called through `bind --mode=browser` binds, see `:help sidebartoggle`") +} + // {{{ CONTAINERS /** Closes all tabs open in the same container across all windows.