mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 08:39:02 +03:00
fix(ui): make Knobs s-to-jump work (#57877)
This commit is contained in:
committed by
GitHub
Unverified
parent
ad0871ebc2
commit
f7f8d94f60
@@ -896,7 +896,7 @@
|
||||
"@solid-primitives/resize-observer": "catalog:",
|
||||
"fuzzysort": "catalog:",
|
||||
"katex": "0.16.47",
|
||||
"knobs": "npm:@kitlangton/knobs@0.2.0",
|
||||
"knobs": "npm:@kitlangton/knobs@0.3.0",
|
||||
"marked": "catalog:",
|
||||
"marked-shiki": "catalog:",
|
||||
"motion": "12.34.5",
|
||||
@@ -4092,7 +4092,7 @@
|
||||
|
||||
"klona": ["klona@2.0.6", "", {}, "sha512-dhG34DXATL5hSxJbIexCft8FChFXtmskoZYnoPWjXQuebWYCNkVeV3KkGegCK9CP1oswI/vQibS2GY7Em/sJJA=="],
|
||||
|
||||
"knobs": ["@kitlangton/knobs@0.2.0", "", { "dependencies": { "@kitlangton/rolling-number": "^0.4.1" }, "peerDependencies": { "react": ">=18", "solid-js": ">=1.8" }, "optionalPeers": ["react", "solid-js"] }, "sha512-U00oAdO2U5LMZsRRe/+DN6qBcEd/RFjSQlZMjNobnNHvAfCyqLOUnCHt44KJWGk9qRj/JHyL3wJZTMKhoqROng=="],
|
||||
"knobs": ["@kitlangton/knobs@0.3.0", "", { "dependencies": { "@kitlangton/rolling-number": "^0.4.1" }, "peerDependencies": { "react": ">=18", "solid-js": ">=1.8" }, "optionalPeers": ["react", "solid-js"] }, "sha512-zdaDcWFUpmntcsKv/VyVJyWKABodHbVFrreSwELNVvnxKJNe23vaAB6qgYNIjQpiUUfJdxkGnmAw41qmPkNfWQ=="],
|
||||
|
||||
"lang-map": ["lang-map@0.4.0", "", { "dependencies": { "language-map": "^1.1.0" } }, "sha512-oiSqZIEUnWdFeDNsp4HId4tAxdFbx5iMBOwA3666Fn2L8Khj8NiD9xRvMsGmKXopPVkaDFtSv3CJOmXFUB0Hcg=="],
|
||||
|
||||
|
||||
@@ -89,6 +89,44 @@ it("closes only from its own close button or Esc inside it, never from the app a
|
||||
expect(closed).toBe(2)
|
||||
})
|
||||
|
||||
it("jumps with s from inside the panel, and leaves s and the backtick outside it alone", async () => {
|
||||
const outside = document.createElement("button")
|
||||
const container = document.createElement("div")
|
||||
document.body.append(outside, container)
|
||||
let closed = 0
|
||||
cleanups.push(mountMotionPanel(container, { onClose: () => closed++ }))
|
||||
|
||||
const panel = await waitFor(() => container.querySelector<HTMLElement>(".knobs-panel") ?? undefined)
|
||||
|
||||
const press = (target: Element, key: string) =>
|
||||
target.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true }))
|
||||
|
||||
outside.focus()
|
||||
press(outside, "s")
|
||||
press(outside, "`")
|
||||
expect(panel.classList.contains("knobs-hinting")).toBe(false)
|
||||
expect(panel.closest("[hidden],[data-leaving]")).toBeNull()
|
||||
|
||||
const random = await waitFor(() => panel.querySelector<HTMLButtonElement>('button[aria-label="Random"]') ?? undefined)
|
||||
random.focus()
|
||||
press(random, "s")
|
||||
expect(panel.classList.contains("knobs-hinting")).toBe(true)
|
||||
const codes = [...panel.querySelectorAll(".knobs-hint")].map((el) => el.textContent ?? "")
|
||||
expect(codes.length).toBeGreaterThan(0)
|
||||
|
||||
// Esc leaves hint mode, not the panel.
|
||||
press(random, "Escape")
|
||||
expect(panel.classList.contains("knobs-hinting")).toBe(false)
|
||||
expect(closed).toBe(0)
|
||||
|
||||
const code = codes.find((item) => item.length === 2) ?? codes[0]!
|
||||
press(random, "s")
|
||||
;[...code].forEach((key) => press(document.activeElement ?? random, key))
|
||||
expect(panel.classList.contains("knobs-hinting")).toBe(false)
|
||||
expect(document.activeElement).not.toBe(random)
|
||||
expect(panel.contains(document.activeElement)).toBe(true)
|
||||
})
|
||||
|
||||
async function waitFor<T>(find: () => T | undefined) {
|
||||
for (let i = 0; i < 200; i++) {
|
||||
const found = find()
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
"@solid-primitives/resize-observer": "catalog:",
|
||||
"fuzzysort": "catalog:",
|
||||
"katex": "0.16.47",
|
||||
"knobs": "npm:@kitlangton/knobs@0.2.0",
|
||||
"knobs": "npm:@kitlangton/knobs@0.3.0",
|
||||
"marked": "catalog:",
|
||||
"marked-shiki": "catalog:",
|
||||
"motion": "12.34.5",
|
||||
|
||||
@@ -118,6 +118,9 @@ export function mountMotionPanel(
|
||||
theme: "auto",
|
||||
title: options.title ?? "Knobs",
|
||||
onClose: options.onClose,
|
||||
// The debug bar shows and hides this panel, and `s` jumps only with focus inside it, so the app keeps its keys.
|
||||
toggleKey: false,
|
||||
hints: "panel",
|
||||
tabs: sections,
|
||||
tab: section,
|
||||
onTab: (id) => (section = id),
|
||||
|
||||
Reference in New Issue
Block a user