mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-05 03:49:53 +00:00
Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: David Hill <1879069+iamdavidhill@users.noreply.github.com> Co-authored-by: BB84 <110078428+BB-84C@users.noreply.github.com> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Sebastian <hasta84@gmail.com> Co-authored-by: Jérôme Benoit <jerome.benoit@sap.com> Co-authored-by: Test User <test@test.com> Co-authored-by: Simon Klee <hello@simonklee.dk> Co-authored-by: Rahul A Mistry <149420892+ProdigyRahul@users.noreply.github.com> Co-authored-by: Qiping Li <liqiping1991@gmail.com> Co-authored-by: liqiping <liqiping@msh.team> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Matthias Reso <13337103+mreso@users.noreply.github.com> Co-authored-by: tobwen <1864057+tobwen@users.noreply.github.com> Co-authored-by: Daniel Polito <danielbpolito@gmail.com> Co-authored-by: opencode <noreply@opencode.ai> Co-authored-by: Devin R Leopold <devin.leopold@gmail.com> Co-authored-by: Zach Bruggeman <mail@bruggie.com> Co-authored-by: Zach Bruggeman <zbruggeman@ramp.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: David Siewert <david1gruppenplan@gmail.com> Co-authored-by: Andrei Dziahel <develop7@develop7.info> Co-authored-by: adityachaudhary99 <adityaachaudhary2003@gmail.com> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: Matt Carey <mcarey@cloudflare.com>
107 lines
3.4 KiB
TypeScript
107 lines
3.4 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { createRoot } from "solid-js"
|
|
import { createKeybindSettingsController } from "../src/components/settings-keybinds"
|
|
|
|
function setup(overrides: Record<string, string> = {}) {
|
|
const changes: [string, string][] = []
|
|
const suppression: boolean[] = []
|
|
const notifications: { title: string; description?: string }[] = []
|
|
let resets = 0
|
|
let controller: ReturnType<typeof createKeybindSettingsController>
|
|
|
|
const dispose = createRoot((dispose) => {
|
|
controller = createKeybindSettingsController(
|
|
{
|
|
command: {
|
|
catalog: [
|
|
{ id: "session.alpha", title: "Alpha", keybind: "mod+a" },
|
|
{ id: "session.beta", title: "Beta", keybind: "mod+b" },
|
|
],
|
|
options: [],
|
|
keybinds: (enabled) => suppression.push(enabled),
|
|
},
|
|
settings: {
|
|
current: { keybinds: overrides },
|
|
keybinds: {
|
|
get: (id) => overrides[id],
|
|
set: (id, value) => {
|
|
overrides[id] = value
|
|
changes.push([id, value])
|
|
},
|
|
resetAll: () => {
|
|
resets++
|
|
},
|
|
},
|
|
},
|
|
notify: (toast) => notifications.push(toast),
|
|
},
|
|
{
|
|
locale: () => "en",
|
|
t: (key, params) => {
|
|
if (params) return `${key}:${Object.values(params).join("|")}`
|
|
if (key === "common.key.alt") return "Alt"
|
|
return String(key)
|
|
},
|
|
},
|
|
)
|
|
return dispose
|
|
})
|
|
|
|
return {
|
|
controller: controller!,
|
|
changes,
|
|
suppression,
|
|
notifications,
|
|
resets: () => resets,
|
|
dispose,
|
|
}
|
|
}
|
|
|
|
function modKey(key: string) {
|
|
const mac = /(Mac|iPod|iPhone|iPad)/.test(navigator.platform)
|
|
return new KeyboardEvent("keydown", { key, ctrlKey: !mac, metaKey: mac, bubbles: true, cancelable: true })
|
|
}
|
|
|
|
describe("keybind settings controller", () => {
|
|
test("derives the catalog, effective bindings, and filtered groups", () => {
|
|
const state = setup({ "session.beta": "alt+k" })
|
|
|
|
expect(state.controller.catalog.title("session.alpha")).toBe("Alpha")
|
|
expect(state.controller.catalog.keybind("session.beta")).toBe("Alt+K")
|
|
expect(state.controller.catalog.filtered("alt k").get("Session")).toEqual(["session.beta"])
|
|
expect(state.controller.settings.hasOverrides()).toBe(true)
|
|
|
|
state.dispose()
|
|
})
|
|
|
|
test("captures bindings, rejects conflicts, and restores command handling", () => {
|
|
const state = setup()
|
|
|
|
state.controller.capture.toggle("session.beta")
|
|
document.dispatchEvent(modKey("a"))
|
|
expect(state.changes).toEqual([])
|
|
expect(state.notifications).toHaveLength(1)
|
|
expect(state.controller.capture.active()).toBe("session.beta")
|
|
|
|
document.dispatchEvent(modKey("x"))
|
|
expect(state.changes).toEqual([["session.beta", "mod+x"]])
|
|
expect(state.suppression).toEqual([false, true])
|
|
expect(state.controller.capture.active()).toBeNull()
|
|
|
|
state.controller.capture.toggle("session.alpha")
|
|
state.dispose()
|
|
expect(state.suppression).toEqual([false, true, false, true])
|
|
document.dispatchEvent(modKey("z"))
|
|
expect(state.changes).toEqual([["session.beta", "mod+x"]])
|
|
})
|
|
|
|
test("resets persisted overrides and reports success", () => {
|
|
const state = setup({ "session.alpha": "none" })
|
|
|
|
state.controller.settings.reset()
|
|
expect(state.resets()).toBe(1)
|
|
expect(state.notifications[0]?.title).toBe("settings.shortcuts.reset.toast.title")
|
|
|
|
state.dispose()
|
|
})
|
|
})
|