Skip to content

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: the dialog opens every file it lists, and says nothing when closed (#98555)

Alice T'Poteat6160717d8994
diff --git a/mods/diff/hooks/drawn-files-of/drawn-files-of.ts b/mods/diff/hooks/drawn-files-of/drawn-files-of.ts
index 3944253c..f94234bf 100644
--- a/mods/diff/hooks/drawn-files-of/drawn-files-of.ts
+++ b/mods/diff/hooks/drawn-files-of/drawn-files-of.ts
@@ -1,25 +1,35 @@
import type Git from '../git'
import Limits from '../limits'
import PaneState from '../pane-state'
+import Views from '../views'
/**
- * The files whose bodies the pane draws now, in drawing order: the listed
- * session rows, then the pre-session rows while their section is open.
+ * The files whose bodies the pane draws or a press opens: every row its
+ * seat lists now.
*
- * Past PRE_SESSION_BODY_CAP pre-session files only their legend shows, so
- * none of their bodies is wanted.
+ * Docked, the listed session rows, then the pre-session rows while their
+ * section is open, none past PRE_SESSION_BODY_CAP. Inline, the rows in the
+ * dialog's window, none for a turn, whose rows carry their own bodies.
*
- * @param model the pane's state: its fetch and its two toggles
+ * @param model the pane's state: its fetch, its seat, its toggles, its pick
* @returns the rows, none without a fetch
*/
export function drawnFilesOf(
- model: Pick<
- PaneState.PaneModel,
- 'data' | 'isNoiseShown' | 'isPreSessionShown'
- >,
+ model: PaneState.PaneModel,
): readonly Git.FileStat[] {
+ const files = model.data?.files ?? []
+
+ if (model.placement === 'inline') {
+ const isTurn = PaneState.pickedTurnOf(model) !== undefined
+ const listed = Views.dialogEntriesOf(model).map(entry => entry.path)
+ const start = Views.dialogWindowOf(model, listed)
+ const windowed = listed.slice(start, start + Limits.MAX_VISIBLE_FILES)
+
+ return files.filter(file => !isTurn && windowed.includes(file.path))
+ }
+
const partition = PaneState.partitionOf(
- model.data?.files ?? [],
+ files,
model.isNoiseShown ? 'shown' : 'hidden',
)
diff --git a/mods/diff/hooks/register.ts b/mods/diff/hooks/register.ts
index 3f20943e..3273ad0a 100644
--- a/mods/diff/hooks/register.ts
+++ b/mods/diff/hooks/register.ts
@@ -544,6 +544,7 @@ export function register(on: On) {
place: isDocked ? Views.placeAtFile(model, path) : model.place,
}
+ void loadBodies(engine).catch(() => undefined)
redraw(engine)
},
scrollList: delta => {
@@ -727,6 +728,15 @@ export function register(on: On) {
columns = e.viewport?.columns ?? columns
+ /**
+ * A seat that changed since the last drawing lists other rows, whose
+ * bodies are read once.
+ *
+ * The model takes the new seat in this same pass, so the drawing that
+ * read asks for finds the seat unchanged.
+ */
+ const isReseated = e.props.placement !== model.placement
+
model = {
...model,
placement: e.props.placement,
@@ -740,6 +750,10 @@ export function register(on: On) {
},
}
+ if (isReseated) {
+ void loadBodies(host).catch(() => undefined)
+ }
+
return Views.paneView(
{
ui: { Box, Text, Button, Select, Code },
@@ -830,13 +844,9 @@ export function register(on: On) {
isPaneOpen = false
}
- const isDialog = model.isFullscreen === false
-
- if (isPersons && host && isDialog) {
- host.uiLog(Names.DIALOG_DISMISSED_TEXT)
- }
+ const isDocking = model.isFullscreen !== false
- if (isPersons && host && !isDialog) {
+ if (isPersons && host && isDocking) {
markTabSwitch(host, 'convo')
await host.storeSet(Names.STORE_OPEN_KEY, false).catch(() => undefined)
}
@@ -859,6 +869,7 @@ export function register(on: On) {
}
model = { ...model, selectedPath: focus.selectedPath }
+ void loadBodies(host).catch(() => undefined)
fitDialog(host)
host.invalidate()
diff --git a/mods/diff/tests/fixtures/index.ts b/mods/diff/tests/fixtures/index.ts
index f6774b1a..55efa567 100644
--- a/mods/diff/tests/fixtures/index.ts
+++ b/mods/diff/tests/fixtures/index.ts
@@ -61,6 +61,7 @@ export * from './usage-at.js'
export * from './vs-main.js'
export * from './wheel-over-list.js'
export * from './wheel-tick.js'
+export * from './with-lockfile.js'
export * from './worktree'
export * from './wrapped-lines'
diff --git a/mods/diff/tests/fixtures/old-files.ts b/mods/diff/tests/fixtures/old-files.ts
index a82ef439..a5001015 100644
--- a/mods/diff/tests/fixtures/old-files.ts
+++ b/mods/diff/tests/fixtures/old-files.ts
@@ -1,17 +1,23 @@
import type { On } from 'claude-code'
/**
- * Answers `$.fs` over /work holding MOVED_IN's two files, both last
- * written at time 0, before any session began.
+ * Answers `$.fs` over /work holding the named files, MOVED_IN's two when
+ * none is given, each last written at time 0, before any session began.
*
* @param on the test's `on`
+ * @param names the files /work holds
*/
-export function oldFiles(on: On) {
+export function oldFiles(
+ on: On,
+ names: readonly string[] = ['old.ts', 'moved.ts'],
+) {
on('fs.list', () => ({
- value: [
- { name: 'old.ts', kind: 'file', size: 2, isLink: false },
- { name: 'moved.ts', kind: 'file', size: 2, isLink: false },
- ],
+ value: names.map(name => ({
+ name,
+ kind: 'file' as const,
+ size: 2,
+ isLink: false,
+ })),
}))
on('fs.stat', () => ({
diff --git a/mods/diff/tests/fixtures/with-lockfile.ts b/mods/diff/tests/fixtures/with-lockfile.ts
new file mode 100644
index 00000000..e1acd81e
--- /dev/null
+++ b/mods/diff/tests/fixtures/with-lockfile.ts
@@ -0,0 +1,10 @@
+import { answersOf } from './answers-of.js'
+
+/**
+ * Git's output in /work where a source file and a lockfile changed, the
+ * lockfile a generated file the docked pane hides until asked.
+ */
+export const WITH_LOCKFILE = answersOf('1\t1\tapp.ts\0' + '1\t1\tbun.lock\0', {
+ 'app.ts': '@@ -1 +1 @@\n-const a = 1\n+const a = 2\n',
+ 'bun.lock': '@@ -1 +1 @@\n-"left": "1.0.0"\n+"left": "1.0.1"\n',
+})
diff --git a/mods/diff/tests/views.test.ts b/mods/diff/tests/views.test.ts
index 7138e166..1ba8ad48 100644
--- a/mods/diff/tests/views.test.ts
+++ b/mods/diff/tests/views.test.ts
@@ -92,6 +92,97 @@ describe('views', () => {
expect(drawn).toContain('\u2191/\u2193 to scroll \u00b7 Esc to back')
})
+ test('inline, a file edited before the session opens too', async ($, on) => {
+ const world = Fixtures.inRepository(on, Fixtures.MOVED_IN)
+
+ on('session.usage', () => ({ value: Fixtures.usageAt(Fixtures.SETTLE_MS) }))
+ Fixtures.oldFiles(on)
+
+ await $.session.start(Fixtures.SESSION)
+ await $.command.run(Fixtures.DIALOG_DIFF)
+ await world.clock.advance(Fixtures.SETTLE_MS)
+
+ expect(
+ Fixtures.textOf(await $.ui.render(Fixtures.INLINE_PANE)),
+ "the dialog lists it beside the session's file",
+ ).toContain('old.ts')
+
+ expect(await $.ui.press({ plugin: 'diff', key: 'file:old.ts' })).toEqual({
+ element: 'file:old.ts',
+ })
+
+ await world.clock.advance(Fixtures.SETTLE_MS)
+
+ const drawn = Fixtures.textOf(await $.ui.render(Fixtures.INLINE_PANE))
+
+ expect(
+ drawn,
+ 'a listed row can be pressed, so its hunks were read',
+ ).not.toContain('Loading diff')
+
+ expect(drawn).toContain('+b')
+ expect(drawn).not.toContain('+d')
+ })
+
+ test('inline, a file the docked pane hides opens too', async ($, on) => {
+ const world = Fixtures.inRepository(on, Fixtures.WITH_LOCKFILE)
+
+ await $.session.start(Fixtures.SESSION)
+ await $.command.run(Fixtures.DIALOG_DIFF)
+ await world.clock.advance(Fixtures.SETTLE_MS)
+ await $.ui.render(Fixtures.INLINE_PANE)
+
+ expect(await $.ui.press({ plugin: 'diff', key: 'file:bun.lock' })).toEqual({
+ element: 'file:bun.lock',
+ })
+
+ await world.clock.advance(Fixtures.SETTLE_MS)
+
+ const drawn = Fixtures.textOf(await $.ui.render(Fixtures.INLINE_PANE))
+
+ expect(drawn, 'generated, and still a listed row').not.toContain(
+ 'Loading diff',
+ )
+
+ expect(drawn).toContain('+"left": "1.0.1"')
+ })
+
+ test('inline, a window that moves reads only its new rows', async ($, on) => {
+ const world = Fixtures.inRepository(on, Fixtures.MANY_FILES)
+
+ on('session.usage', () => ({ value: Fixtures.usageAt(Fixtures.SETTLE_MS) }))
+
+ Fixtures.oldFiles(
+ on,
+ Array.from(
+ { length: Fixtures.MANY_FILE_COUNT },
+ (_, at) => `file${at}.ts`,
+ ),
+ )
+
+ await $.session.start(Fixtures.SESSION)
+ await $.command.run(Fixtures.DIALOG_DIFF)
+ await world.clock.advance(Fixtures.SETTLE_MS)
+ await $.ui.render(Fixtures.INLINE_PANE)
+ await world.clock.advance(Fixtures.SETTLE_MS)
+ await $.ui.focus(Fixtures.ringOnto('file:file3.ts'))
+ await world.clock.advance(Fixtures.SETTLE_MS)
+ await $.ui.render(Fixtures.INLINE_PANE)
+ await $.ui.press({ plugin: 'diff', key: 'file:file5.ts' })
+ await world.clock.advance(Fixtures.SETTLE_MS)
+
+ expect(
+ world.runs
+ .filter(run => run.argv.includes('--raw'))
+ .map(run => run.argv.slice(run.argv.indexOf('--') + 1).join(' ')),
+ 'the first five, the one the walk brought in, the two the press did',
+ ).toEqual([
+ 'file0.ts file1.ts file2.ts file3.ts file4.ts',
+ 'file5.ts',
+ 'file6.ts file7.ts',
+ ])
+ })
+
test('docked, a wheel tick moves the body, not the list', async ($, on) => {
const world = Fixtures.inRepository(on, Fixtures.MANY_FILES)