mirror of
https://github.com/vale981/tridactyl
synced 2025-03-04 17:11:40 -05:00
Merge pull request #4641 from tridactyl/toggle_sidebar
Add (secret) sidebar toggle command for browser binds
This commit is contained in:
commit
d21b430a3c
3 changed files with 57 additions and 8 deletions
|
@ -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(" "))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue