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's selected row starts the focus ring (autoFocus) and the ring's walk selects, the five rows re-centring on it as the built-in's do (ui.focus)
poteatdf235907a990
diff --git a/mods/diff/hooks/names/index.ts b/mods/diff/hooks/names/index.tsindex 7192f90e..70e4a632 100644--- a/mods/diff/hooks/names/index.ts+++ b/mods/diff/hooks/names/index.ts@@ -3,6 +3,7 @@ export * from './command-name.js'export * from './keys'export * from './pane-id.js'export * from './pane-title.js'+export * from './plugin-name.js'export * from './texts'export * as default from '.'diff --git a/mods/diff/hooks/names/plugin-name.ts b/mods/diff/hooks/names/plugin-name.tsnew file mode 100644index 00000000..69f71134--- /dev/null+++ b/mods/diff/hooks/names/plugin-name.ts@@ -0,0 +1,5 @@+/**+ * The plugin's own name, as the engine stamps it on the elements its render+ * hooks draw (`ui.press`, `ui.focus`).+ */+export const PLUGIN_NAME = 'diff'diff --git a/mods/diff/hooks/pane-state/dialog-focus/dialog-focus.ts b/mods/diff/hooks/pane-state/dialog-focus/dialog-focus.tsnew file mode 100644index 00000000..03616566--- /dev/null+++ b/mods/diff/hooks/pane-state/dialog-focus/dialog-focus.ts@@ -0,0 +1,8 @@+/**+ * What the ring landing on a dialog row settles: the file now selected,+ * and the key of the row to land the ring on once the window re-centres.+ */+export type DialogFocus = {+ selectedPath: string+ landing: string+}diff --git a/mods/diff/hooks/pane-state/dialog-focus/index.ts b/mods/diff/hooks/pane-state/dialog-focus/index.tsnew file mode 100644index 00000000..f85ca7bd--- /dev/null+++ b/mods/diff/hooks/pane-state/dialog-focus/index.ts@@ -0,0 +1,3 @@+export type * from './dialog-focus.js'++export * as default from '.'diff --git a/mods/diff/hooks/pane-state/index.ts b/mods/diff/hooks/pane-state/index.tsindex 91aeab9c..33e7edfa 100644--- a/mods/diff/hooks/pane-state/index.ts+++ b/mods/diff/hooks/pane-state/index.ts@@ -2,6 +2,7 @@ export * from './after-fetch'export * from './after-new-session'export * from './base-mode-of'export * from './bodies'+export * from './dialog-focus'export * from './dialog-title'export * from './dialog-title-of.js'export * from './empty-state'diff --git a/mods/diff/hooks/register.ts b/mods/diff/hooks/register.tsindex df521103..a471e185 100644--- a/mods/diff/hooks/register.ts+++ b/mods/diff/hooks/register.ts@@ -467,13 +467,7 @@ export function register(on: On) {redraw(engine)},scrollList: delta => {- const place = Views.listScrolledBy(model, delta)- const isDocked = model.placement === 'dock'-- model = isDocked- ? { ...model, place }- : { ...model, place, selectedPath: null }-+ model = { ...model, place: Views.listScrolledBy(model, delta) }redraw(engine)},toggleNoise: () => {@@ -729,6 +723,23 @@ export function register(on: On) {return result})+ on('ui.focus', { plugin: Names.PLUGIN_NAME }, ($, e, next) => {+ const isListed =+ model.placement === 'inline' && model.dialogView === 'list' && host++ const focus = isListed ? Views.dialogFocusOf(model, e.element) : null++ if (!focus || !host) {+ return next(e)+ }++ model = { ...model, selectedPath: focus.selectedPath }+ fitDialog(host)+ host.invalidate()++ return next({ ...e, element: focus.landing })+ })+on('ui.scroll', { requestId: Names.PANE_ID }, ($, e, next) => {const isOwnBody = e.origin.kind === 'person' && model.placement === 'dock'diff --git a/mods/diff/hooks/views/body/list-scrolled-by.ts b/mods/diff/hooks/views/body/list-scrolled-by.tsindex 4b512dca..d31e6fd3 100644--- a/mods/diff/hooks/views/body/list-scrolled-by.ts+++ b/mods/diff/hooks/views/body/list-scrolled-by.ts@@ -1,11 +1,10 @@import Limits from '../../limits'import type PaneState from '../../pane-state'-import DialogPane from '../dialog-pane'import Plan from './plan'/**- * The pane's place with its list window moved by so many files, clamped:- * docked, ReplDiffSidebar's scrollSummary; inline, the dialog's window.+ * The docked pane's place with the list window moved by so many files,+ * clamped to the list (ReplDiffSidebar's scrollSummary).** @param model the pane's state* @param delta the files to move by, negative toward the top@@ -15,19 +14,16 @@ export function listScrolledBy(model: PaneState.PaneModel,delta: number,): PaneState.PaneModel['place'] {- const isDocked = model.placement === 'dock'- const paths = DialogPane.dialogEntriesOf(model).map(entry => entry.path)-- const last = isDocked- ? Plan.dockPlanOf(model).rows.length - Limits.MAX_SUMMARY_ROWS- : paths.length - Limits.MAX_VISIBLE_FILES-- const start = isDocked- ? Math.min(model.place.listStart, Math.max(0, last))- : DialogPane.dialogWindowOf(model, paths)+ const last = Math.max(+ 0,+ Plan.dockPlanOf(model).rows.length - Limits.MAX_SUMMARY_ROWS,+ )return {...model.place,- listStart: Math.max(0, Math.min(Math.max(0, last), start + delta)),+ listStart: Math.max(+ 0,+ Math.min(last, Math.min(model.place.listStart, last) + delta),+ ),}}diff --git a/mods/diff/hooks/views/dialog-pane/dialog-focus-of.ts b/mods/diff/hooks/views/dialog-pane/dialog-focus-of.tsnew file mode 100644index 00000000..2af340a3--- /dev/null+++ b/mods/diff/hooks/views/dialog-pane/dialog-focus-of.ts@@ -0,0 +1,32 @@+import type PaneState from '../../pane-state'+import Sections from '../sections'+import { dialogEntriesOf } from './dialog-entries-of'+import { dialogWindowOf } from './dialog-window-of'++/**+ * What the focus ring landing on a dialog row makes of the list: that file+ * selected, the window re-centred, the key of the row drawn where it sits.+ *+ * DiffFileList's selection. The engine keeps its ring by position, so the+ * ring is sent to the row that holds the selected file's place once the+ * window has moved; null for a key that is none of the listed rows'.+ *+ * @param model the pane's state+ * @param element the key of the element taking the ring+ * @returns the selected path and the key to land the ring on, or null+ */+export function dialogFocusOf(+ model: PaneState.PaneModel,+ element: string | undefined,+): PaneState.DialogFocus | null {+ const entries = dialogEntriesOf(model)+ const paths = entries.map(entry => entry.path)+ const keys = entries.map(entry => Sections.fileKeyOf(entry))+ const picked = keys.indexOf(element ?? '')+ const selectedPath = paths[picked] ?? null+ const after = dialogWindowOf({ selectedPath }, paths)+ const landing = keys[dialogWindowOf(model, paths) + picked - after]+ const isRow = selectedPath !== null && landing !== undefined++ return isRow ? { selectedPath, landing } : null+}diff --git a/mods/diff/hooks/views/dialog-pane/dialog-pane.tsx b/mods/diff/hooks/views/dialog-pane/dialog-pane.tsxindex 3ebf7922..0d669a60 100644--- a/mods/diff/hooks/views/dialog-pane/dialog-pane.tsx+++ b/mods/diff/hooks/views/dialog-pane/dialog-pane.tsx@@ -18,9 +18,9 @@ import { dialogWindowOf } from './dialog-window-of'* The inline pane (DiffDialog): its title, the dim count, then the file* list's window, or the picked file's detail alone, and the key hints.*- * Every file lists in the built-in's order, five at a time between `more- * files` rows that move the window; the source picker stands in for the- * tabs. Arrows walk the rows, Enter views one, Escape backs out or closes.+ * Every file lists in the built-in's order, five at a time round the+ * selected row (`❯ `, where the focus ring starts and what its walk moves,+ * ui.focus); Enter views that file, Escape backs out or closes.** @param kit the elements, the handlers, the width* @param model the pane's state@@ -44,6 +44,7 @@ export function dialogPane(const isTurn = model.source.kind === 'turn'const isPaged = entries.length > Limits.MAX_VISIBLE_FILESconst picked = entries.find(entry => entry.path === model.selectedPath)+ const selected = picked ?? entries[0]const isDetail = model.dialogView === 'detail' && picked !== undefinedconst start = dialogWindowOf(@@ -89,7 +90,7 @@ export function dialogPane(added: entry.added,removed: entry.removed,note: noteOf(entry),- isSelected: false,+ isSelected: entry === selected,},() => kit.actions.selectFile(entry.path),)@@ -97,9 +98,8 @@ export function dialogPane(function moreOf(way: 'up' | 'down', count: number): RenderElement {const arrow = way === 'up' ? '\u2191' : '\u2193'const words = Layout.plural(count, 'file').replace(' ', ' more ')- const edge = way === 'up' ? 'files-up' : 'files-down'- return Sections.listEdgeButton(kit, edge, ` ${arrow} ${words}`)+ return Sections.dimNote(kit, ` ${arrow} ${words}`)}const pagedEdgeOf = (way: 'up' | 'down', count: number) =>diff --git a/mods/diff/hooks/views/dialog-pane/dialog-window-of/dialog-window-of.ts b/mods/diff/hooks/views/dialog-pane/dialog-window-of/dialog-window-of.tsindex 9c438e2e..71090dc9 100644--- a/mods/diff/hooks/views/dialog-pane/dialog-window-of/dialog-window-of.ts+++ b/mods/diff/hooks/views/dialog-pane/dialog-window-of/dialog-window-of.ts@@ -3,23 +3,21 @@ import type PaneState from '../../../pane-state'/*** The first of the MAX_VISIBLE_FILES rows the dialog lists (DiffFileList's- * window): centred on the file last viewed, else where its edge rows put it.+ * window): centred on the selected file, the first when none is, clamped.*- * @param model the pane's state: the pick and the list's start+ * @param model the pane's state: the selection* @param paths the listed files' paths, in order* @returns the first listed row's index*/-export function dialogWindowOf(- model: Pick<PaneState.PaneModel, 'selectedPath' | 'place'>,+export const dialogWindowOf = (+ model: Pick<PaneState.PaneModel, 'selectedPath'>,paths: readonly string[],-): number {- const last = Math.max(0, paths.length - Limits.MAX_VISIBLE_FILES)- const picked = paths.indexOf(model.selectedPath ?? '')- const isPicked = model.selectedPath !== null && picked >= 0-- const wanted = isPicked- ? picked - Math.floor(Limits.MAX_VISIBLE_FILES / 2)- : model.place.listStart-- return Math.max(0, Math.min(last, wanted))-}+): number =>+ Math.max(+ 0,+ Math.min(+ paths.length - Limits.MAX_VISIBLE_FILES,+ Math.max(0, paths.indexOf(model.selectedPath ?? '')) -+ Math.floor(Limits.MAX_VISIBLE_FILES / 2),+ ),+ )diff --git a/mods/diff/hooks/views/dialog-pane/index.ts b/mods/diff/hooks/views/dialog-pane/index.tsindex 25ab7b31..3cf665d2 100644--- a/mods/diff/hooks/views/dialog-pane/index.ts+++ b/mods/diff/hooks/views/dialog-pane/index.ts@@ -1,4 +1,5 @@export * from './dialog-entries-of'+export * from './dialog-focus-of.js'export * from './dialog-pane.jsx'export * from './dialog-rows-of.js'export * from './dialog-window-of'diff --git a/mods/diff/hooks/views/pane-actions/pane-actions.ts b/mods/diff/hooks/views/pane-actions/pane-actions.tsindex b78b9d53..67db0f5c 100644--- a/mods/diff/hooks/views/pane-actions/pane-actions.ts+++ b/mods/diff/hooks/views/pane-actions/pane-actions.ts@@ -10,8 +10,7 @@ export type PaneActions = {selectFile: (path: string) => void/**- * Moves the list's window by so many files, clamped to the list; in the- * dialog the pick is dropped so the window leaves the file last viewed.+ * Moves the docked list's window by so many files, clamped to the list.*/scrollList: (delta: number) => voiddiff --git a/mods/diff/hooks/views/sections/dialog-file-row/dialog-file-row.tsx b/mods/diff/hooks/views/sections/dialog-file-row/dialog-file-row.tsxindex dbab4b78..71be6778 100644--- a/mods/diff/hooks/views/sections/dialog-file-row/dialog-file-row.tsx+++ b/mods/diff/hooks/views/sections/dialog-file-row/dialog-file-row.tsx@@ -14,7 +14,7 @@ import { POINTER } from '../pointer'/*** One file of the inline list (DiffFileList FileItem): the pointer before- * the selected one, the start-truncated name, its counts or note right.+ * the selected one, where the focus ring starts, the name, counts or note.** @param kit the elements, the handlers, the width* @param row the file@@ -42,7 +42,13 @@ export function dialogFileRow(return listRow(kit,- { key: row.key, label: `${mark} ${name}`, onPress, isDim: false },+ {+ key: row.key,+ label: `${mark} ${name}`,+ onPress,+ isDim: false,+ isAutoFocus: row.isSelected,+ },tail,)}diff --git a/mods/diff/hooks/views/sections/file-row/file-row.ts b/mods/diff/hooks/views/sections/file-row/file-row.tsindex 015eaad1..7a9d4ac5 100644--- a/mods/diff/hooks/views/sections/file-row/file-row.ts+++ b/mods/diff/hooks/views/sections/file-row/file-row.ts@@ -36,7 +36,7 @@ export function fileRow(return listRow(kit,- { key: row.key, label, onPress, isDim: true },+ { key: row.key, label, onPress, isDim: true, isAutoFocus: false },diffStat(kit, row.added, row.removed),)}diff --git a/mods/diff/hooks/views/sections/keyed-pressable/keyed-pressable.ts b/mods/diff/hooks/views/sections/keyed-pressable/keyed-pressable.tsindex 2d9c219d..7725f8d5 100644--- a/mods/diff/hooks/views/sections/keyed-pressable/keyed-pressable.ts+++ b/mods/diff/hooks/views/sections/keyed-pressable/keyed-pressable.ts@@ -2,9 +2,10 @@ import type { Pressable } from '../pressable'/*** A plain Button's face, press and address: a list row's Button, dim at- * rest where the built-in draws the row dim.+ * rest where the built-in's is, the focus ring's start where selected.*/export type KeyedPressable = Pressable & {key: stringisDim: boolean+ isAutoFocus: boolean}diff --git a/mods/diff/hooks/views/sections/list-edge-button/list-edge-button.tsx b/mods/diff/hooks/views/sections/list-edge-button/list-edge-button.tsxindex 71a0ebf1..6840f0fc 100644--- a/mods/diff/hooks/views/sections/list-edge-button/list-edge-button.tsx+++ b/mods/diff/hooks/views/sections/list-edge-button/list-edge-button.tsx@@ -3,39 +3,32 @@/* @jsxFrag Fragment */import type { RenderElement } from 'claude-code'-import Limits from '../../../limits'import type { Kit } from '../../kit'/**- * A list's `more` row as a dim plain Button that moves its window: the- * docked list's a file, under the built-in's keys too; the dialog's a page.- *- * The built-in dialog moves its window with the selection; a plugin cannot- * see the person walk the rows, so there the row itself carries the move.+ * The docked list's `more above` or `more below` row as a dim plain Button+ * that moves its window a file, under the built-in's list keys too.** @param kit the elements and the handlers- * @param edge which list and which edge, the Button's key+ * @param edge which edge, the Button's key* @param label the row's text* @returns the Button*/export function listEdgeButton(kit: Kit,- edge: 'list-up' | 'list-down' | 'files-up' | 'files-down',+ edge: 'list-up' | 'list-down',label: string,): RenderElement {const { Button } = kit.ui- const isDocked = edge === 'list-up' || edge === 'list-down'- const isUp = edge === 'list-up' || edge === 'files-up'- const size = isDocked ? 1 : Limits.MAX_VISIBLE_FILES- const action = isUp ? 'app:diffFileListUp' : 'app:diffFileListDown'+ const isUp = edge === 'list-up'return (<Buttonkey={edge}plaindimColor- {...(isDocked ? { action } : {})}- onPress={() => kit.actions.scrollList(isUp ? -size : size)}+ action={isUp ? 'app:diffFileListUp' : 'app:diffFileListDown'}+ onPress={() => kit.actions.scrollList(isUp ? -1 : 1)}>{label}</Button>diff --git a/mods/diff/hooks/views/sections/list-row/list-row.tsx b/mods/diff/hooks/views/sections/list-row/list-row.tsxindex a1d4ba38..3a50414c 100644--- a/mods/diff/hooks/views/sections/list-row/list-row.tsx+++ b/mods/diff/hooks/views/sections/list-row/list-row.tsx@@ -7,12 +7,12 @@ import type { Kit } from '../../kit'import type { KeyedPressable } from '../keyed-pressable'/**- * One row of a file list: a plain Button under its key, then whatever the- * row shows at its right edge (its counts, a note).+ * One list row: a plain Button as wide as its label, a spacer, then the+ * tail at the right edge (the counts, or a note).** @param kit the elements- * @param row the Button's key, label and press, and whether it rests dim- * @param tail the element at the right edge+ * @param row the Button's key, label, press, rest style and ring start+ * @param tail what sits at the row's right edge* @returns the row element*/export function listRow(@@ -24,7 +24,13 @@ export function listRow(return (<Box flexDirection="row">- <Button key={row.key} plain dimColor={row.isDim} onPress={row.onPress}>+ <Button+ key={row.key}+ plain+ dimColor={row.isDim}+ {...(row.isAutoFocus ? ({ autoFocus: true } as const) : {})}+ onPress={row.onPress}+ >{row.label}</Button><Box flexGrow={1} />