|
1 | | -import type { On, ResultOf, SessionMessage, Timer } from 'claude-code' |
| 1 | +import type { |
| 2 | + On, |
| 3 | + PaneOpenArgs, |
| 4 | + ResultOf, |
| 5 | + SessionMessage, |
| 6 | + Timer, |
| 7 | +} from 'claude-code' |
2 | 8 |
|
3 | 9 | import Ask from './ask' |
4 | 10 | import Backend from './backend' |
@@ -35,6 +41,7 @@ export function register(on: On) { |
35 | 41 | let probing: Promise<boolean> | null = null |
36 | 42 | let sessionStartMs = 0 |
37 | 43 | let isPaneOpen = false |
| 44 | + let dialogRows: number | null = null |
38 | 45 | let hasAutoOpened = false |
39 | 46 | let columns: number | null = null |
40 | 47 | let shownSessionId: string | null = null |
@@ -141,7 +148,31 @@ export function register(on: On) { |
141 | 148 | return true |
142 | 149 | } |
143 | 150 |
|
| 151 | + function dialogPane(): PaneOpenArgs { |
| 152 | + return { |
| 153 | + id: Names.PANE_ID, |
| 154 | + title: Names.PANE_TITLE, |
| 155 | + holdToasts: true, |
| 156 | + closeOnEscape: true, |
| 157 | + rows: Views.dialogRowsOf(model), |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + function fitDialog(engine: Host) { |
| 162 | + const rows = Views.dialogRowsOf(model) |
| 163 | + |
| 164 | + const isStale = |
| 165 | + isPaneOpen && model.isFullscreen === false && rows !== dialogRows |
| 166 | + |
| 167 | + if (isStale) { |
| 168 | + dialogRows = rows |
| 169 | + void engine.openPane(dialogPane()).catch(() => undefined) |
| 170 | + } |
| 171 | + } |
| 172 | + |
144 | 173 | function redraw(engine: Host) { |
| 174 | + fitDialog(engine) |
| 175 | + |
145 | 176 | if (timers.has('redraw')) { |
146 | 177 | return |
147 | 178 | } |
@@ -352,12 +383,13 @@ export function register(on: On) { |
352 | 383 | place: { ...model.place, top: 0, listStart: 0 }, |
353 | 384 | } |
354 | 385 |
|
355 | | - await engine.openPane({ |
356 | | - id: Names.PANE_ID, |
357 | | - title: Names.PANE_TITLE, |
358 | | - holdToasts: true, |
359 | | - ...(isDialog ? ({ focus: true, closeOnEscape: true } as const) : {}), |
360 | | - }) |
| 386 | + dialogRows = isDialog ? Views.dialogRowsOf(model) : null |
| 387 | + |
| 388 | + await engine.openPane( |
| 389 | + isDialog |
| 390 | + ? { ...dialogPane(), focus: true } |
| 391 | + : { id: Names.PANE_ID, title: Names.PANE_TITLE, holdToasts: true }, |
| 392 | + ) |
361 | 393 |
|
362 | 394 | isPaneOpen = true |
363 | 395 |
|
@@ -666,14 +698,10 @@ export function register(on: On) { |
666 | 698 | model = { ...model, dialogView: 'list' } |
667 | 699 | redraw(host) |
668 | 700 |
|
| 701 | + dialogRows = Views.dialogRowsOf(model) |
| 702 | + |
669 | 703 | void host |
670 | | - .openPane({ |
671 | | - id: Names.PANE_ID, |
672 | | - title: Names.PANE_TITLE, |
673 | | - focus: true, |
674 | | - closeOnEscape: true, |
675 | | - holdToasts: true, |
676 | | - }) |
| 704 | + .openPane({ ...dialogPane(), focus: true }) |
677 | 705 | .catch(() => undefined) |
678 | 706 |
|
679 | 707 | return { deny: 'back to the file list' } |
@@ -708,7 +736,15 @@ export function register(on: On) { |
708 | 736 | return next(e) |
709 | 737 | } |
710 | 738 |
|
711 | | - model = { ...model, place: Views.bodyScrolledBy(model, e) } |
| 739 | + const isOverList = Views.isWheelOverList(model, e) |
| 740 | + |
| 741 | + model = { |
| 742 | + ...model, |
| 743 | + place: isOverList |
| 744 | + ? Views.listScrolledBy(model, e.by) |
| 745 | + : Views.bodyScrolledBy(model, e), |
| 746 | + } |
| 747 | + |
712 | 748 | host.invalidate() |
713 | 749 |
|
714 | 750 | return {} |
|
0 commit comments