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 wheel over a list longer than its window moves the list (ui.scroll's pointer), and the dialog opens as tall as its content (ui.open's rows)

poteat4025de58b16f
diff --git a/mods/diff/hooks/register.ts b/mods/diff/hooks/register.ts
index 94a8b69d..df521103 100644
--- a/mods/diff/hooks/register.ts
+++ b/mods/diff/hooks/register.ts
@@ -1,4 +1,10 @@
-import type { On, ResultOf, SessionMessage, Timer } from 'claude-code'
+import type {
+ On,
+ PaneOpenArgs,
+ ResultOf,
+ SessionMessage,
+ Timer,
+} from 'claude-code'
import Ask from './ask'
import Backend from './backend'
@@ -35,6 +41,7 @@ export function register(on: On) {
let probing: Promise<boolean> | null = null
let sessionStartMs = 0
let isPaneOpen = false
+ let dialogRows: number | null = null
let hasAutoOpened = false
let columns: number | null = null
let shownSessionId: string | null = null
@@ -141,7 +148,31 @@ export function register(on: On) {
return true
}
+ function dialogPane(): PaneOpenArgs {
+ return {
+ id: Names.PANE_ID,
+ title: Names.PANE_TITLE,
+ holdToasts: true,
+ closeOnEscape: true,
+ rows: Views.dialogRowsOf(model),
+ }
+ }
+
+ function fitDialog(engine: Host) {
+ const rows = Views.dialogRowsOf(model)
+
+ const isStale =
+ isPaneOpen && model.isFullscreen === false && rows !== dialogRows
+
+ if (isStale) {
+ dialogRows = rows
+ void engine.openPane(dialogPane()).catch(() => undefined)
+ }
+ }
+
function redraw(engine: Host) {
+ fitDialog(engine)
+
if (timers.has('redraw')) {
return
}
@@ -352,12 +383,13 @@ export function register(on: On) {
place: { ...model.place, top: 0, listStart: 0 },
}
- await engine.openPane({
- id: Names.PANE_ID,
- title: Names.PANE_TITLE,
- holdToasts: true,
- ...(isDialog ? ({ focus: true, closeOnEscape: true } as const) : {}),
- })
+ dialogRows = isDialog ? Views.dialogRowsOf(model) : null
+
+ await engine.openPane(
+ isDialog
+ ? { ...dialogPane(), focus: true }
+ : { id: Names.PANE_ID, title: Names.PANE_TITLE, holdToasts: true },
+ )
isPaneOpen = true
@@ -666,14 +698,10 @@ export function register(on: On) {
model = { ...model, dialogView: 'list' }
redraw(host)
+ dialogRows = Views.dialogRowsOf(model)
+
void host
- .openPane({
- id: Names.PANE_ID,
- title: Names.PANE_TITLE,
- focus: true,
- closeOnEscape: true,
- holdToasts: true,
- })
+ .openPane({ ...dialogPane(), focus: true })
.catch(() => undefined)
return { deny: 'back to the file list' }
@@ -708,7 +736,15 @@ export function register(on: On) {
return next(e)
}
- model = { ...model, place: Views.bodyScrolledBy(model, e) }
+ const isOverList = Views.isWheelOverList(model, e)
+
+ model = {
+ ...model,
+ place: isOverList
+ ? Views.listScrolledBy(model, e.by)
+ : Views.bodyScrolledBy(model, e),
+ }
+
host.invalidate()
return {}
diff --git a/mods/diff/hooks/views/body/body-scrolled-by.ts b/mods/diff/hooks/views/body/body-scrolled-by.ts
index 30fe104e..8363e933 100644
--- a/mods/diff/hooks/views/body/body-scrolled-by.ts
+++ b/mods/diff/hooks/views/body/body-scrolled-by.ts
@@ -5,8 +5,8 @@ import type PaneState from '../../pane-state'
import Plan from './plan'
/**
- * The docked pane's place after one of the person's scrolls: a wheel tick
- * or arrow three rows, a page key the window's rows, Home and End the ends.
+ * The docked pane's place after one of the person's scrolls of the body:
+ * a wheel tick or arrow three rows, a page key the window, Home/End an end.
*
* Told apart by the rows the move asks for against the pane's body and
* tree, as the engine sizes each; clamped to the body's extent.
diff --git a/mods/diff/hooks/views/body/index.ts b/mods/diff/hooks/views/body/index.ts
index b52fa40e..37d56a6e 100644
--- a/mods/diff/hooks/views/body/index.ts
+++ b/mods/diff/hooks/views/body/index.ts
@@ -1,5 +1,6 @@
export * from './body-scrolled-by.js'
export * from './draw-window.jsx'
+export * from './is-wheel-over-list.js'
export * from './list-block-of.jsx'
export * from './list-scrolled-by.js'
export * from './place-at-file.js'
diff --git a/mods/diff/hooks/views/body/is-wheel-over-list.ts b/mods/diff/hooks/views/body/is-wheel-over-list.ts
new file mode 100644
index 00000000..b111731e
--- /dev/null
+++ b/mods/diff/hooks/views/body/is-wheel-over-list.ts
@@ -0,0 +1,28 @@
+import type { UiScrollInput } from 'claude-code'
+
+import Limits from '../../limits'
+import type PaneState from '../../pane-state'
+import Plan from './plan'
+
+/**
+ * Whether a scroll is a wheel tick over the docked list block while the
+ * list overflows its window: it moves the list then, as ReplDiffSidebar's.
+ *
+ * @param model the pane's state
+ * @param scroll the move: the cell the wheel was over, absent for keys
+ * @returns whether the list takes it
+ */
+export function isWheelOverList(
+ model: PaneState.PaneModel,
+ scroll: Pick<UiScrollInput, 'pointer'>,
+): boolean {
+ const plan = Plan.dockPlanOf(model)
+ const { listTop, listEnd } = Plan.bodyLayoutOf(model, plan)
+ const row = scroll.pointer?.row ?? -1
+
+ return (
+ row >= listTop &&
+ row < listEnd &&
+ plan.rows.length > Limits.MAX_SUMMARY_ROWS
+ )
+}
diff --git a/mods/diff/hooks/views/body/plan/body-layout-of.ts b/mods/diff/hooks/views/body/plan/body-layout-of.ts
index c8c72252..3c3ae6cb 100644
--- a/mods/diff/hooks/views/body/plan/body-layout-of.ts
+++ b/mods/diff/hooks/views/body/plan/body-layout-of.ts
@@ -5,7 +5,7 @@ import Segments from './segments'
/**
* The docked pane's scrolling body laid out under its pinned rows: the
- * segments, their rows, the window's rows, where each file's block starts.
+ * segments and their rows, the window's rows, the files' and list's rows.
*
* The pinned rows are counted as sidebarPane draws them (header, base or
* turn line, todo bar, list block); read from the box last drawn (`place`),
@@ -54,11 +54,15 @@ export function bodyLayoutOf(
extent += Segments.segmentRowsOf(segment)
}
+ const listTop = Limits.PANE_TOP_PAD_ROWS + headRows + 1
+
return {
segments,
extent,
visibleRows,
maxTop: Math.max(0, extent - visibleRows),
tops,
+ listTop,
+ listEnd: hasList ? listTop + listRows - 2 : listTop,
}
}
diff --git a/mods/diff/hooks/views/body/types/body-layout.ts b/mods/diff/hooks/views/body/types/body-layout.ts
index 2f1a854c..51e389f3 100644
--- a/mods/diff/hooks/views/body/types/body-layout.ts
+++ b/mods/diff/hooks/views/body/types/body-layout.ts
@@ -1,8 +1,8 @@
import type { Segment } from './segment'
/**
- * The docked pane's scrolling body laid out: its segments, their rows in
- * all, the window's rows, its last top, the row each file's block starts.
+ * The docked pane's scrolling body laid out: its segments and their rows,
+ * the window, each file's first row, the list block's rows (end exclusive).
*/
export type BodyLayout = {
segments: readonly Segment[]
@@ -10,4 +10,6 @@ export type BodyLayout = {
visibleRows: number
maxTop: number
tops: ReadonlyMap<string, number>
+ listTop: number
+ listEnd: number
}
diff --git a/mods/diff/hooks/views/dialog-pane/dialog-rows-of.ts b/mods/diff/hooks/views/dialog-pane/dialog-rows-of.ts
new file mode 100644
index 00000000..0c0fd3ef
--- /dev/null
+++ b/mods/diff/hooks/views/dialog-pane/dialog-rows-of.ts
@@ -0,0 +1,46 @@
+import Limits from '../../limits'
+import PaneState from '../../pane-state'
+import { dialogEntriesOf } from './dialog-entries-of'
+import { dialogWindowOf } from './dialog-window-of'
+
+/**
+ * The rows the dialog's content takes as dialogPane draws it, for the
+ * `rows` an inline open asks for: title, blank, count, picker, body, hints.
+ *
+ * The body is the message line, the list's window with its `more files`
+ * rows, or the file's name, rule and hunk lines (their wraps not counted:
+ * the layout caps a long file anyway and its arrows scroll it).
+ *
+ * @param model the pane's state
+ * @returns the rows wanted
+ */
+export function dialogRowsOf(model: PaneState.PaneModel): number {
+ const entries = dialogEntriesOf(model)
+
+ const hasCount =
+ PaneState.pickedTurnOf(model) !== undefined || model.data !== null
+
+ const isPaged = entries.length > Limits.MAX_VISIBLE_FILES
+ const picked = entries.find(entry => entry.path === model.selectedPath)
+ const isDetail = model.dialogView === 'detail' && picked !== undefined
+
+ const start = dialogWindowOf(
+ model,
+ entries.map(entry => entry.path),
+ )
+
+ const lines = (picked?.body?.hunks ?? []).reduce(
+ (sum, hunk) => sum + 1 + hunk.lines.length,
+ 0,
+ )
+
+ const listed = Math.min(entries.length - start, Limits.MAX_VISIBLE_FILES)
+
+ const isEmpty = entries.length === 0
+ const listRows = isEmpty ? 1 : listed + (isPaged ? 2 : 0)
+ const bodyRows = isDetail ? 2 + Math.max(1, lines) : listRows
+
+ return (
+ 2 + Number(hasCount) + Number(model.turns.length > 0) + 2 + bodyRows + 1
+ )
+}
diff --git a/mods/diff/hooks/views/dialog-pane/index.ts b/mods/diff/hooks/views/dialog-pane/index.ts
index 4e53d06e..25ab7b31 100644
--- a/mods/diff/hooks/views/dialog-pane/index.ts
+++ b/mods/diff/hooks/views/dialog-pane/index.ts
@@ -1,5 +1,6 @@
export * from './dialog-entries-of'
export * from './dialog-pane.jsx'
+export * from './dialog-rows-of.js'
export * from './dialog-window-of'
export * from './list-body-of'
export * from './message-pane-of'