Fix #5493: add :splitnext

This commit is contained in:
Oliver Blanthorn 2026-07-31 21:38:25 +02:00
parent 9c8c15ff77
commit fb7d2feeef
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
4 changed files with 38 additions and 0 deletions

View file

@ -217,6 +217,27 @@ test("`changelistjump` skips closed tabs", async () => {
])
})
test.each([
[7, [[2, { active: true }]]],
[-1, []],
[undefined, []],
])(
"`splitnext` handles split view ID %s",
async (splitViewId, expectedCalls) => {
const query = jest.mocked(browser.tabs.query)
const update = jest.mocked(browser.tabs.update)
update.mockClear()
query.mockResolvedValueOnce([
{ id: 1, active: true, splitViewId },
{ id: 2, active: false, splitViewId },
] as browser.tabs.Tab[])
await backgroundExcmds.splitnext()
expect(query).toHaveBeenLastCalledWith({ currentWindow: true })
expect(update.mock.calls).toEqual(expectedCalls)
},
)
test("`nativeopen` targets the running macOS Firefox application", async () => {
jest.mocked(browser.runtime.getPlatformInfo).mockResolvedValue({
arch: "x86-64",

View file

@ -2739,6 +2739,16 @@ async function tabIndexSetActive(index: number | string) {
return tabSetActive(await idFromIndex(index))
}
/** Switch focus to the other side of the current split view, if it exists */
//#background
export async function splitnext() {
const tabs = await browser.tabs.query({ currentWindow: true })
const splitViewId = tabs.find(tab => tab.active)?.splitViewId
if (splitViewId === undefined || splitViewId < 0) return
const next = tabs.find(tab => !tab.active && tab.splitViewId === splitViewId)
if (next) return tabSetActive(next.id)
}
/** Switch to the first tab in Firefox's tab order. */
//#background
export async function tabfirst() {

View file

@ -325,6 +325,7 @@ export class default_config {
K: "tabnext",
gt: "tabnext_gt",
gT: "tabprev",
gs: "splitnext", // c-w w is reserved for closing windows
// "<c-n>": "tabnext_gt", // c-n is reserved for new window
// "<c-p>": "tabprev",
"g^": "tabfirst",

6
src/tridactyl.d.ts vendored
View file

@ -20,6 +20,12 @@ interface HTMLElement {
openOrClosedShadowRoot: ShadowRoot | null
}
declare namespace browser.tabs {
interface Tab {
splitViewId?: number
}
}
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
// these functions really can be anything, ditto for the objects
declare function exportFunction(