From ff43d5ac426c898e6eace33bbc6957e8eeb9eed7 Mon Sep 17 00:00:00 2001 From: Yash Bavadiya Date: Thu, 26 Nov 2026 15:19:22 +0530 Subject: [PATCH 1/2] fix: let an open dialog keep the keys instead of the diagram behind it --- src/App.keyboard.test.tsx | 43 +++++++++++++++++++++++++++++++++++++++ src/App.tsx | 13 ++++++++++++ src/components/Canvas.tsx | 8 +++++++- src/present.ts | 11 +++++++++- 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/App.keyboard.test.tsx b/src/App.keyboard.test.tsx index 983680c..8f784d9 100644 --- a/src/App.keyboard.test.tsx +++ b/src/App.keyboard.test.tsx @@ -320,3 +320,46 @@ describe('one rail at a time on a tablet held upright', () => { expect(saved.library).not.toBe(false); }); }); + +describe('keys while a dialog is open', () => { + const share = () => + document.querySelector('button[aria-label="Share"]')!; + const dialog = () => document.querySelector('[aria-modal="true"]'); + const playLabel = () => + document + .querySelector( + 'button[aria-label="Pause"], button[aria-label="Play"]', + ) + ?.getAttribute('aria-label'); + + it('leaves the diagram and the panels alone behind it', () => { + mount(); + press(node('mine-cache')); + press(share()); + expect(dialog()).not.toBeNull(); + const panels = body().value; + const running = playLabel(); + + key('Delete'); + key('Backspace'); + key('c'); + key('m'); + key(' ', { code: 'Space' } as KeyboardEventInit); + key('s'); + + expect(node('mine-cache')).not.toBeNull(); + expect(body().value).toBe(panels); + expect(playLabel()).toBe(running); + + key('Escape'); + // It closes with a short animation. + act(() => { + vi.advanceTimersByTime(500); + }); + expect(dialog()).toBeNull(); + // With it closed, the same key reaches the diagram again. + press(node('mine-cache')); + key('Delete'); + expect(node('mine-cache')).toBeNull(); + }); +}); diff --git a/src/App.tsx b/src/App.tsx index e56b482..41550f9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -110,6 +110,7 @@ import { buildCommands, type CommandActions, type CommandFacts } from './appComm import { loadRecent, pushRecent, saveRecent, type Command } from './commands'; import { canFullscreen, + dialogOpen, toggleFullscreen, useFocusedPart, useFullscreen, @@ -4465,6 +4466,17 @@ export default function App() { } } + // An open dialog owns the keys: Space on one of its buttons presses + // the button, not play, and C does not fold a panel behind it. The + // two keys that toggle a dialog still close their own. + if (dialogOpen()) { + const plain = !e.metaKey && !e.ctrlKey && !e.altKey; + const closesOwn = + (e.key === '?' && plain && glossaryOpen) || + ((e.ctrlKey || e.metaKey) && e.code === 'Slash' && shortcutsOpen); + if (!closesOwn) return; + } + /* * Undo / redo. Bound by e.code, not e.key: KeyZ is the physical key in * the Z position, so the chord works on layouts (Cyrillic, Greek) where @@ -4631,6 +4643,7 @@ export default function App() { handleDuplicate, setSpeed, glossaryOpen, + shortcutsOpen, openGlossary, closeGlossary, toggleLibrary, diff --git a/src/components/Canvas.tsx b/src/components/Canvas.tsx index 067eefb..3f56602 100644 --- a/src/components/Canvas.tsx +++ b/src/components/Canvas.tsx @@ -1,3 +1,4 @@ +import { dialogOpen } from '../present'; import { createElement, memo, @@ -646,8 +647,13 @@ const nodeRect = (n: SimNode) => ({ x: n.x, y: n.y, w: NODE_W, h: NODE_H }); const EMPTY_SELECTION: ReadonlySet = new Set(); -/** True when the event should not be intercepted by a canvas key handler. */ +/** + * True when the event should not be intercepted by a canvas key handler: the + * reader is typing in a field, or a dialog is open and owns the keys, so + * Delete in Share cannot remove the box selected behind it. + */ function isTypingTarget(t: EventTarget | null): boolean { + if (dialogOpen()) return true; const el = t as HTMLElement | null; if (!el || typeof el.tagName !== 'string') return false; const tag = el.tagName; diff --git a/src/present.ts b/src/present.ts index 3f160a8..40de8ca 100644 --- a/src/present.ts +++ b/src/present.ts @@ -24,6 +24,15 @@ export function isTypingTarget(t: EventTarget | null): boolean { ); } +/** + * Whether a dialog (Share, Settings, the palette, the glossary...) is open. + * It owns the keyboard then: a letter, Space or Delete pressed in it must + * not reach the diagram behind it. + */ +export function dialogOpen(): boolean { + return document.querySelector('[aria-modal="true"]') !== null; +} + /** What a key press means here, or null for a key this mode leaves alone. */ export function presentKeyAction( e: Pick< @@ -130,7 +139,7 @@ export function usePresenting( useEffect(() => { const onKey = (e: KeyboardEvent) => { // A dialog (the palette, the shortcuts, a picker) owns the keys. - if (document.querySelector('[aria-modal="true"]')) return; + if (dialogOpen()) return; const act = presentKeyAction(e, live.current); if (act === null) return; e.preventDefault(); From e68727785d4bb4f30f7afd830ecd1cc3907a1526 Mon Sep 17 00:00:00 2001 From: Yash Bavadiya Date: Thu, 26 Nov 2026 15:19:23 +0530 Subject: [PATCH 2/2] fix(learn): say "its only slot" instead of "all 1 slots" --- src/learn/bottleneck.test.ts | 15 +++++++++++++++ src/learn/bottleneck.ts | 15 +++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/learn/bottleneck.test.ts b/src/learn/bottleneck.test.ts index 474aa8e..56433eb 100644 --- a/src/learn/bottleneck.test.ts +++ b/src/learn/bottleneck.test.ts @@ -77,6 +77,21 @@ describe('findBottleneck', () => { expect(wrong).toEqual([]); }, 60_000); + it('says "its only slot" for a part with one slot, not "all 1 slots"', () => { + const t = preset('single-server'); + const db = idOf(t, 'Database'); + const one: Topology = { + ...t, + nodes: t.nodes.map((n) => + n.id === db ? { ...n, config: { ...n.config, capacity: 1, instances: 1 } } : n, + ), + }; + const run = runFor(one, 10); + expect(problemAt(run)).toBe(db); + expect(run.verdict.text).toContain('Database: its only slot busy'); + expect(run.verdict.text).not.toContain('all 1 '); + }); + it('names the database in the single server example at 270 a second', () => { const run = runFor(scaled(preset('single-server'), 5.4), 10); const db = idOf(run.topology, 'Database'); diff --git a/src/learn/bottleneck.ts b/src/learn/bottleneck.ts index d5015fe..a1da0e7 100644 --- a/src/learn/bottleneck.ts +++ b/src/learn/bottleneck.ts @@ -327,6 +327,11 @@ export function findBottleneck(topology: Topology, snapshot: SimSnapshot): Verdi /* ---------------- the sentences ---------------- */ +/** "all 6 slots", or "its only slot" when there is one: "all 1 slots" is not English. */ +function allOf(n: number, one: string, many: string): string { + return n === 1 ? `its only ${one}` : `all ${formatCount(n)} ${many}`; +} + /** "all 6 slots busy, 34 waiting in line", or the closest honest phrase for the kind. */ export function stateClause( r: Reading, @@ -341,18 +346,20 @@ export function stateClause( // Full only because calls hold slots: the box reads busy as the working // share alone, so a bare "all busy" would contradict it. parts.push( - `all ${formatCount(slots)} slots taken, ${formatCount(r.s.inFlight)} working and ${formatCount(held)} waiting on its calls`, + `${allOf(slots, 'slot', 'slots')} taken, ${formatCount(r.s.inFlight)} working and ${formatCount(held)} waiting on its calls`, ); } else if (slots !== null) { - parts.push(`all ${formatCount(slots)} slots busy`); + parts.push(`${allOf(slots, 'slot', 'slots')} busy`); } else if (r.node.kind === 'shard') { parts.push(`its busiest partition is at ${formatPct(r.fill)}`); } else if (r.node.kind === 'lambda') { parts.push( - `all ${formatCount(r.node.config.maxConcurrency ?? 0)} copies running`, + `${allOf(r.node.config.maxConcurrency ?? 0, 'copy', 'copies')} running`, ); } else if (r.node.kind === 'websocket') { - parts.push(`all ${formatCount(r.s.maxConnections ?? 0)} connections in use`); + parts.push( + `${allOf(r.s.maxConnections ?? 0, 'connection', 'connections')} in use`, + ); } else { parts.push(`${formatPct(r.fill)} busy`); }