Merge pull request #4641 from tridactyl/toggle_sidebar

Add (secret) sidebar toggle command for browser binds
This commit is contained in:
Oliver Blanthorn 2023-03-24 15:31:40 +00:00 committed by GitHub
commit d21b430a3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 8 deletions

View file

@ -6,12 +6,14 @@ import * as controller from "@src/lib/controller"
function makelistener(commands: Array<browser.commands.Command>) {
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(" "))
}
}

View file

@ -36,6 +36,19 @@ function escapehatch() {
})()
}
export const useractions: Record<string, () => void> = {
escapehatch,
/**
* Toggle the sidebar. Bind with e.g. `:bind --mode=browser <C-.> sidebartoggle`
*/
function sidebartoggle() {
return browser.sidebarAction.toggle()
}
function jsua(...args: string[]) {
return eval(args.join(" "))
}
export const useractions: Record<string, (...args: string[]) => void> = {
escapehatch,
sidebartoggle,
jsua,
}

View file

@ -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 <C-.> 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 <C-.> 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.