Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
TypeScript
diff tests and README: the walk selects and the window follows
poteat01e6ae421fc1
diff --git a/mods/diff/README.md b/mods/diff/README.mdindex 6afab1db..ee047cc3 100644--- a/mods/diff/README.md+++ b/mods/diff/README.md@@ -22,9 +22,10 @@ built-in's line asking for a wider one and nothing opens. Without thatlayout (`CLAUDE_CODE_NO_FLICKER=0`, which `/diff` learns from the command's`presentation`) the pane opens inline at any width, focused and as tallas its content (the open's `rows`), in the built-in dialog's shape: the-title, the count, five file rows at a time between `more files` rows that-page them, the key hints; the arrows walk the rows, Enter shows that-file's hunks alone,+title, the count, five file rows at a time round the selected one (`❯`,+where the focus ring starts; the plugin follows the ring's walk through+`ui.focus` and re-centres the rows as the built-in does), the key hints;+Enter shows that file's hunks alone,Escape backs out to the list and then closes, leaving `Diff dialogdismissed`; toasts are held while it is up. A file's ask button arms thatfile: its hunks ride the next prompt as context, once.@@ -52,6 +53,7 @@ asked for; a rename lists as git prints it. Outside a git repository| `command.run` of `diff` | Opens or closes the pane (focused and closing on Escape without the fullscreen layout), says which, and remembers the choice. || `ui.close` of the pane | Backs out of the dialog's detail view instead of closing; else remembers the person's close as `/diff`'s. || `ui.scroll` of the pane | Docked, moves the hunks under the pinned header and list (three rows a wheel tick, a page a page key), or the list when the wheel is over it, and keeps the engine's window still. |+| `ui.focus` in the pane | In the dialog's list, selects the file the ring lands on, re-centres the five rows on it, and lands the ring where that row now sits. || `command.run` of `clear`, `resume` | Closes the pane and forgets the session's state. || `tool.call` of `Edit`, `Write`, `NotebookEdit` | After the edit, refreshes an open pane; the session's first successful edit opens it. || `tool.call` of `Bash`, `PowerShell` | After the command, refreshes an open pane. |diff --git a/mods/diff/tests/fixtures/in-repository.ts b/mods/diff/tests/fixtures/in-repository.tsindex 2e731120..f3671078 100644--- a/mods/diff/tests/fixtures/in-repository.ts+++ b/mods/diff/tests/fixtures/in-repository.ts@@ -22,6 +22,7 @@ export function inRepository(answers: Readonly<Record<string, string>> = REPOSITORY,) {const runs: Args<'process.run'>[] = []+ const focused: Args<'ui.focus'>[] = []const opened = keeping<Args<'ui.open'>>()const closed = keeping<Args<'ui.close'>>()const clock = startsSession(on)@@ -32,6 +33,12 @@ export function inRepository(return { value: gitIn(e.argv, answers) }})+ on('ui.focus', (_engine, e) => {+ focused.push(e)++ return {}+ })+on('ui.open', opened.hook)on('ui.close', closed.hook)on('ui.invalidate', () => ({ value: undefined }))@@ -39,5 +46,5 @@ export function inRepository(on('session.messages', () => ({ value: [] }))mock.store(on)- return { runs, opened: opened.kept, closed: closed.kept, clock }+ return { runs, focused, opened: opened.kept, closed: closed.kept, clock }}diff --git a/mods/diff/tests/fixtures/index.ts b/mods/diff/tests/fixtures/index.tsindex 45b4f52d..0f66f26e 100644--- a/mods/diff/tests/fixtures/index.ts+++ b/mods/diff/tests/fixtures/index.ts@@ -19,6 +19,7 @@ export * from './pane.js'export * from './renamed.js'export * from './repository.js'export * from './repository-of.js'+export * from './ring-onto.js'export * from './session.js'export * from './settle-ms.js'export * from './starts-session.js'diff --git a/mods/diff/tests/fixtures/ring-onto.ts b/mods/diff/tests/fixtures/ring-onto.tsnew file mode 100644index 00000000..3871a3c4--- /dev/null+++ b/mods/diff/tests/fixtures/ring-onto.ts@@ -0,0 +1,18 @@+import type { UiFocusInput } from 'claude-code'++import { PANE } from './pane.js'++/**+ * The person walking the pane's focus ring onto one of the plugin's+ * elements, as the engine raises it before the ring moves.+ *+ * @param key the element's key+ * @returns the `ui.focus` input+ */+export const ringOnto = (key: string): UiFocusInput => ({+ component: 'Pane',+ requestId: PANE.requestId,+ plugin: 'diff',+ element: key,+ origin: { kind: 'person' },+})diff --git a/mods/diff/tests/views.test.ts b/mods/diff/tests/views.test.tsindex 74632ea8..077f5c32 100644--- a/mods/diff/tests/views.test.ts+++ b/mods/diff/tests/views.test.ts@@ -140,7 +140,7 @@ describe('views', () => {expect(drawn).toContain('Uncommitted changes (git diff HEAD)')expect(drawn).toContain('2 files changed +3 -1')- expect(drawn).toContain(' app.ts')+ expect(drawn).toContain('\u276f app.ts')expect(drawn).toContain(' lib.ts')expect(drawn).not.toContain('+const a = 2')@@ -171,7 +171,7 @@ describe('views', () => {)})- test('off fullscreen, forty files list five at a time', async ($, on) => {+ test('off fullscreen, the window follows the walk', async ($, on) => {const world = Fixtures.inRepository(on, Fixtures.MANY_FILES)await $.session.start(Fixtures.SESSION)@@ -180,19 +180,24 @@ describe('views', () => {const drawn = Fixtures.textOf(await $.ui.render(Fixtures.INLINE_PANE))+ expect(drawn).toContain('\u276f file0.ts')expect(drawn).toContain(' file4.ts')expect(drawn).not.toContain('file5.ts')expect(drawn).toContain(' \u2193 5 more files')+ expect(await $.ui.focus(Fixtures.ringOnto('file:file3.ts'))).toEqual({})- expect(await $.ui.press({ plugin: 'diff', key: 'files-down' })).toEqual({- element: 'files-down',- })+ expect(+ world.focused.map(focus => focus.element),+ 'its row once centred',+ ).toEqual(['file:file2.ts'])- const paged = Fixtures.textOf(await $.ui.render(Fixtures.INLINE_PANE))+ const walked = Fixtures.textOf(await $.ui.render(Fixtures.INLINE_PANE))- expect(paged).toContain(' \u2191 5 more files')- expect(paged).toContain(' file9.ts')- expect(paged).not.toContain('file4.ts')+ expect(walked).toContain(' \u2191 1 more file')+ expect(walked).toContain('\u276f file3.ts')+ expect(walked).toContain(' file5.ts')+ expect(walked).toContain(' \u2193 4 more files')+ expect(walked).not.toContain('file0.ts')})test('off fullscreen, the dialog draws at any width', async ($, on) => {