@zyro-sec/tui 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (573) hide show
  1. package/AGENTS.md +6 -6
  2. package/bunfig.toml +4 -4
  3. package/package.json +11 -11
  4. package/src/app.tsx +1632 -1632
  5. package/src/attention-sounds.bun.ts +8 -8
  6. package/src/attention-sounds.node.ts +16 -16
  7. package/src/attention.ts +189 -189
  8. package/src/audio.d.ts +9 -9
  9. package/src/audio.ts +49 -49
  10. package/src/clipboard.ts +68 -68
  11. package/src/component/background-image.tsx +26 -26
  12. package/src/component/command-palette.tsx +74 -74
  13. package/src/component/devtools-bar.tsx +611 -611
  14. package/src/component/dialog-agent.tsx +33 -33
  15. package/src/component/dialog-background.tsx +102 -102
  16. package/src/component/dialog-config.tsx +494 -494
  17. package/src/component/dialog-debug.tsx +90 -90
  18. package/src/component/dialog-error-details.tsx +130 -130
  19. package/src/component/dialog-experiments.tsx +101 -101
  20. package/src/component/dialog-go-upsell.tsx +448 -448
  21. package/src/component/dialog-highlights.tsx +88 -88
  22. package/src/component/dialog-image-preview.tsx +85 -85
  23. package/src/component/dialog-install-mcp.tsx +25 -3
  24. package/src/component/dialog-integration.tsx +1332 -1332
  25. package/src/component/dialog-mcp.tsx +184 -184
  26. package/src/component/dialog-model-free.tsx +79 -79
  27. package/src/component/dialog-model.tsx +238 -238
  28. package/src/component/dialog-open.tsx +509 -509
  29. package/src/component/dialog-pair.tsx +123 -123
  30. package/src/component/dialog-session-list.tsx +328 -328
  31. package/src/component/dialog-session-rename.tsx +37 -37
  32. package/src/component/dialog-shell-output.tsx +194 -194
  33. package/src/component/dialog-skill.tsx +93 -93
  34. package/src/component/dialog-speed.tsx +48 -48
  35. package/src/component/dialog-stash.tsx +90 -90
  36. package/src/component/dialog-status.tsx +50 -50
  37. package/src/component/dialog-theme-list.tsx +56 -56
  38. package/src/component/dialog-update.tsx +144 -144
  39. package/src/component/dialog-variant.tsx +43 -43
  40. package/src/component/dialog-workspace-file-changes.tsx +187 -187
  41. package/src/component/dialog-workspaces.tsx +413 -413
  42. package/src/component/dialog-worktree-name.tsx +40 -40
  43. package/src/component/error-component.tsx +258 -258
  44. package/src/component/fade-in-text.tsx +113 -113
  45. package/src/component/go-upsell-art.ts +338 -338
  46. package/src/component/logo.tsx +79 -79
  47. package/src/component/masked-text.ts +59 -59
  48. package/src/component/media-source.ts +43 -43
  49. package/src/component/migration-overlay.tsx +73 -73
  50. package/src/component/model-options.tsx +121 -121
  51. package/src/component/one-cell-spinner.tsx +75 -75
  52. package/src/component/panel-host.tsx +64 -64
  53. package/src/component/patch-diff.tsx +211 -211
  54. package/src/component/plugin-route-missing.tsx +21 -21
  55. package/src/component/prompt/autocomplete.tsx +1005 -1005
  56. package/src/component/prompt/draft-stash.ts +47 -47
  57. package/src/component/prompt/index.tsx +2080 -2080
  58. package/src/component/prompt/local-attachment.ts +188 -188
  59. package/src/component/prompt/metadata.tsx +193 -193
  60. package/src/component/prompt/move.tsx +181 -181
  61. package/src/component/reconnecting.tsx +40 -40
  62. package/src/component/retry-provider.tsx +202 -202
  63. package/src/component/session-frame.tsx +408 -408
  64. package/src/component/session-tabs-rail.tsx +94 -94
  65. package/src/component/session-tabs.tsx +1789 -1789
  66. package/src/component/shimmer-text.tsx +64 -64
  67. package/src/component/spinner-frames.ts +1 -1
  68. package/src/component/spinner-renderable.ts +126 -126
  69. package/src/component/spinner.tsx +50 -50
  70. package/src/component/startup-loading.tsx +63 -63
  71. package/src/component/tab-pulse.tsx +819 -819
  72. package/src/component/terminal-pane.tsx +377 -377
  73. package/src/component/theme-error-toast.tsx +20 -20
  74. package/src/component/title-shimmer.tsx +272 -272
  75. package/src/component/todo-item.tsx +27 -27
  76. package/src/component/usage.tsx +329 -329
  77. package/src/component/use-connected.tsx +14 -14
  78. package/src/config/index.tsx +438 -438
  79. package/src/config/keybind.ts +367 -367
  80. package/src/config/new-session-location.ts +16 -16
  81. package/src/config/v1/index.tsx +149 -149
  82. package/src/config/v1/keybind.ts +463 -463
  83. package/src/context/args.tsx +31 -31
  84. package/src/context/attention.tsx +23 -23
  85. package/src/context/client-mcp.tsx +119 -119
  86. package/src/context/client.tsx +76 -76
  87. package/src/context/clipboard.tsx +19 -19
  88. package/src/context/data.tsx +69 -69
  89. package/src/context/editor.ts +408 -408
  90. package/src/context/epilogue.tsx +14 -14
  91. package/src/context/event.ts +32 -32
  92. package/src/context/exit.tsx +8 -8
  93. package/src/context/helper.tsx +26 -26
  94. package/src/context/interactivity.tsx +20 -20
  95. package/src/context/keymap.tsx +515 -515
  96. package/src/context/local.tsx +723 -723
  97. package/src/context/location.tsx +80 -80
  98. package/src/context/log.tsx +24 -24
  99. package/src/context/panel.tsx +59 -59
  100. package/src/context/path-format.tsx +12 -12
  101. package/src/context/permission.tsx +18 -18
  102. package/src/context/program-status.ts +94 -94
  103. package/src/context/prompt.tsx +18 -18
  104. package/src/context/route.tsx +73 -73
  105. package/src/context/runtime.tsx +98 -98
  106. package/src/context/session-tabs-model.ts +263 -263
  107. package/src/context/session-tabs.tsx +508 -508
  108. package/src/context/session-terminals.tsx +136 -136
  109. package/src/context/storage.tsx +150 -150
  110. package/src/context/theme.tsx +447 -447
  111. package/src/context/thinking.ts +20 -20
  112. package/src/context/update-notification.tsx +158 -158
  113. package/src/devtools/index.ts +41 -41
  114. package/src/editor-zed-sqlite.bun.ts +1 -1
  115. package/src/editor-zed-sqlite.node.ts +21 -21
  116. package/src/editor-zed.ts +277 -277
  117. package/src/editor.ts +86 -86
  118. package/src/feature-plugins/home/footer.tsx +116 -116
  119. package/src/feature-plugins/prompt/btw.tsx +190 -190
  120. package/src/feature-plugins/prompt/footer.tsx +163 -163
  121. package/src/feature-plugins/prompt/goal.tsx +211 -211
  122. package/src/feature-plugins/sidebar/context.tsx +52 -52
  123. package/src/feature-plugins/sidebar/footer.tsx +126 -126
  124. package/src/feature-plugins/sidebar/limit.tsx +47 -47
  125. package/src/feature-plugins/sidebar/mcp.tsx +103 -103
  126. package/src/feature-plugins/sidebar/todo.tsx +58 -58
  127. package/src/feature-plugins/system/diff-viewer-file-menu.tsx +87 -87
  128. package/src/feature-plugins/system/diff-viewer-file-tree-utils.ts +174 -174
  129. package/src/feature-plugins/system/diff-viewer-file-tree.tsx +274 -274
  130. package/src/feature-plugins/system/diff-viewer-image.tsx +96 -96
  131. package/src/feature-plugins/system/diff-viewer.tsx +1380 -1380
  132. package/src/feature-plugins/system/notifications.ts +102 -102
  133. package/src/feature-plugins/system/plugins.tsx +356 -356
  134. package/src/feature-plugins/system/stats-data.ts +18 -18
  135. package/src/feature-plugins/system/stats.tsx +217 -217
  136. package/src/feature-plugins/system/storybook/footer.tsx +51 -51
  137. package/src/feature-plugins/system/storybook/highlights.tsx +71 -71
  138. package/src/feature-plugins/system/storybook/index.tsx +153 -153
  139. package/src/feature-plugins/system/storybook/link-clicks.tsx +125 -125
  140. package/src/feature-plugins/system/storybook/merman-layouts.tsx +200 -200
  141. package/src/feature-plugins/system/storybook/one-cell-spinner.fixtures.ts +144 -144
  142. package/src/feature-plugins/system/storybook/one-cell-spinner.tsx +293 -293
  143. package/src/feature-plugins/system/storybook/session-location-missing.tsx +80 -80
  144. package/src/feature-plugins/system/storybook/session-tabs.tsx +571 -571
  145. package/src/feature-plugins/system/storybook/subcell-spinner.fixtures.ts +115 -115
  146. package/src/feature-plugins/system/storybook/todo.tsx +166 -166
  147. package/src/index.tsx +2 -2
  148. package/src/logo.ts +21 -21
  149. package/src/mini/catalog.shared.ts +116 -116
  150. package/src/mini/demo.ts +1086 -1086
  151. package/src/mini/entry.body.ts +244 -244
  152. package/src/mini/footer.command.tsx +1205 -1205
  153. package/src/mini/footer.form.tsx +647 -647
  154. package/src/mini/footer.menu.tsx +313 -313
  155. package/src/mini/footer.permission.tsx +562 -562
  156. package/src/mini/footer.prompt.tsx +1533 -1533
  157. package/src/mini/footer.subagent.tsx +268 -268
  158. package/src/mini/footer.ts +1193 -1193
  159. package/src/mini/footer.view.tsx +1022 -1022
  160. package/src/mini/footer.width.ts +118 -118
  161. package/src/mini/form.shared.ts +241 -241
  162. package/src/mini/index.ts +7 -7
  163. package/src/mini/mono.ts +277 -277
  164. package/src/mini/permission.shared.ts +199 -199
  165. package/src/mini/prompt.editor.ts +74 -74
  166. package/src/mini/prompt.shared.ts +192 -192
  167. package/src/mini/runtime.boot.ts +98 -98
  168. package/src/mini/runtime.lifecycle.ts +393 -393
  169. package/src/mini/runtime.queue.ts +320 -320
  170. package/src/mini/runtime.ts +1117 -1117
  171. package/src/mini/scrollback.shared.ts +82 -82
  172. package/src/mini/scrollback.surface.ts +548 -548
  173. package/src/mini/scrollback.writer.tsx +380 -380
  174. package/src/mini/session-data.ts +13 -13
  175. package/src/mini/session.shared.ts +113 -113
  176. package/src/mini/splash.ts +307 -307
  177. package/src/mini/stream-v2.fragment.ts +83 -83
  178. package/src/mini/stream-v2.image.ts +38 -38
  179. package/src/mini/stream-v2.subagent.ts +1130 -1130
  180. package/src/mini/stream-v2.transport.ts +1916 -1916
  181. package/src/mini/stream.ts +152 -152
  182. package/src/mini/theme.ts +328 -328
  183. package/src/mini/tool.public.ts +3 -3
  184. package/src/mini/tool.ts +1394 -1394
  185. package/src/mini/turn-summary.ts +21 -21
  186. package/src/mini/types.ts +482 -482
  187. package/src/mini/variant.shared.ts +58 -58
  188. package/src/mini/verbosity.ts +84 -84
  189. package/src/model-preference.ts +206 -206
  190. package/src/parsers-config.ts +386 -386
  191. package/src/plugin/api.tsx +486 -486
  192. package/src/plugin/builtins.ts +35 -35
  193. package/src/plugin/context.tsx +757 -757
  194. package/src/plugin/discovery.ts +67 -67
  195. package/src/plugin/markdown.ts +18 -18
  196. package/src/plugin/render.tsx +116 -116
  197. package/src/plugin/runtime-plugin-support.bun.ts +11 -11
  198. package/src/plugin/runtime-plugin-support.node.ts +1 -1
  199. package/src/plugin/source.ts +1 -1
  200. package/src/plugin/structure.ts +159 -159
  201. package/src/plugin/watch.ts +113 -113
  202. package/src/prompt/attachment.ts +97 -97
  203. package/src/prompt/codec.ts +61 -61
  204. package/src/prompt/content.ts +22 -22
  205. package/src/prompt/directory-completion.ts +97 -97
  206. package/src/prompt/directory-recents.ts +36 -36
  207. package/src/prompt/display.ts +41 -41
  208. package/src/prompt/frecency.tsx +80 -80
  209. package/src/prompt/history.tsx +175 -175
  210. package/src/prompt/mention.ts +173 -173
  211. package/src/prompt/parse.ts +25 -25
  212. package/src/prompt/part.ts +35 -35
  213. package/src/prompt/restore.ts +39 -39
  214. package/src/prompt/stash.tsx +93 -93
  215. package/src/prompt/traits.ts +29 -29
  216. package/src/routes/home.tsx +180 -180
  217. package/src/routes/session/activity-summary.ts +101 -101
  218. package/src/routes/session/anchor-view.tsx +53 -53
  219. package/src/routes/session/anchors.ts +85 -85
  220. package/src/routes/session/composer/context.ts +24 -24
  221. package/src/routes/session/composer/index.tsx +143 -143
  222. package/src/routes/session/composer/scripts-tab.tsx +166 -166
  223. package/src/routes/session/composer/shell-tab.tsx +149 -149
  224. package/src/routes/session/composer/subagents-tab.tsx +264 -264
  225. package/src/routes/session/composer/tabs.ts +91 -91
  226. package/src/routes/session/composer/terminals-tab.tsx +114 -114
  227. package/src/routes/session/dialog-execute.tsx +276 -276
  228. package/src/routes/session/dialog-fork.tsx +87 -87
  229. package/src/routes/session/dialog-message.tsx +89 -89
  230. package/src/routes/session/dialog-timeline.tsx +43 -43
  231. package/src/routes/session/form.tsx +1177 -1177
  232. package/src/routes/session/group-view.tsx +407 -407
  233. package/src/routes/session/grouping/session.ts +184 -184
  234. package/src/routes/session/grouping/tree.ts +111 -111
  235. package/src/routes/session/history.ts +59 -59
  236. package/src/routes/session/index.tsx +3922 -3922
  237. package/src/routes/session/location-missing.tsx +81 -81
  238. package/src/routes/session/message-navigation.ts +48 -48
  239. package/src/routes/session/message-parts.tsx +322 -322
  240. package/src/routes/session/mount-budget.ts +38 -38
  241. package/src/routes/session/permission.tsx +622 -622
  242. package/src/routes/session/render-context.tsx +44 -44
  243. package/src/routes/session/rows.ts +493 -493
  244. package/src/routes/session/sidebar.tsx +80 -80
  245. package/src/routes/session/thinking-syntax.ts +8 -8
  246. package/src/runtime.tsx +1 -1
  247. package/src/simulation/semantics.ts +12 -12
  248. package/src/theme/assets/aura.json +69 -69
  249. package/src/theme/assets/ayu.json +80 -80
  250. package/src/theme/assets/carbonfox.json +248 -248
  251. package/src/theme/assets/catppuccin-frappe.json +230 -230
  252. package/src/theme/assets/catppuccin-macchiato.json +230 -230
  253. package/src/theme/assets/catppuccin.json +112 -112
  254. package/src/theme/assets/cobalt2.json +225 -225
  255. package/src/theme/assets/cursor.json +249 -249
  256. package/src/theme/assets/dracula.json +219 -219
  257. package/src/theme/assets/everforest.json +241 -241
  258. package/src/theme/assets/flexoki.json +237 -237
  259. package/src/theme/assets/github.json +233 -233
  260. package/src/theme/assets/gruvbox.json +242 -242
  261. package/src/theme/assets/kanagawa.json +77 -77
  262. package/src/theme/assets/lucent-orng.json +234 -234
  263. package/src/theme/assets/material.json +235 -235
  264. package/src/theme/assets/matrix.json +77 -77
  265. package/src/theme/assets/mercury.json +252 -252
  266. package/src/theme/assets/monokai.json +221 -221
  267. package/src/theme/assets/nightowl.json +221 -221
  268. package/src/theme/assets/nord.json +223 -223
  269. package/src/theme/assets/one-dark.json +84 -84
  270. package/src/theme/assets/opencode.json +245 -245
  271. package/src/theme/assets/orng.json +249 -249
  272. package/src/theme/assets/osaka-jade.json +93 -93
  273. package/src/theme/assets/palenight.json +222 -222
  274. package/src/theme/assets/rosepine.json +234 -234
  275. package/src/theme/assets/solarized.json +223 -223
  276. package/src/theme/assets/synthwave84.json +226 -226
  277. package/src/theme/assets/tokyonight.json +243 -243
  278. package/src/theme/assets/v2/opencode-classic.json +387 -387
  279. package/src/theme/assets/v2/opencode.json +395 -395
  280. package/src/theme/assets/vercel.json +245 -245
  281. package/src/theme/assets/vesper.json +218 -218
  282. package/src/theme/assets/zenburn.json +223 -223
  283. package/src/theme/color.ts +48 -48
  284. package/src/theme/component.ts +51 -51
  285. package/src/theme/discovery.ts +21 -21
  286. package/src/theme/index.ts +109 -109
  287. package/src/theme/resolve.ts +53 -53
  288. package/src/theme/system.ts +144 -144
  289. package/src/theme/v1.ts +70 -70
  290. package/src/ui/animation.ts +235 -235
  291. package/src/ui/border.ts +21 -21
  292. package/src/ui/dialog-alert.tsx +51 -51
  293. package/src/ui/dialog-confirm.tsx +62 -62
  294. package/src/ui/dialog-export-options.tsx +316 -316
  295. package/src/ui/dialog-export-result.tsx +84 -84
  296. package/src/ui/dialog-help.tsx +40 -40
  297. package/src/ui/dialog-prompt.tsx +180 -180
  298. package/src/ui/dialog-select.tsx +1006 -1006
  299. package/src/ui/dialog.tsx +560 -560
  300. package/src/ui/file-path.tsx +112 -112
  301. package/src/ui/layout.ts +26 -26
  302. package/src/ui/link.tsx +51 -51
  303. package/src/ui/one-cell-motion.ts +111 -111
  304. package/src/ui/pane-resize-handle.tsx +33 -33
  305. package/src/ui/pane-resize.ts +76 -76
  306. package/src/ui/select-controller.ts +45 -45
  307. package/src/ui/session-link.ts +92 -92
  308. package/src/ui/spinner.ts +368 -368
  309. package/src/ui/subcell.ts +37 -37
  310. package/src/ui/toast.tsx +222 -222
  311. package/src/ui/working-directory-actions.tsx +66 -66
  312. package/src/util/collapse-tool-output.ts +95 -95
  313. package/src/util/config-directories.ts +53 -53
  314. package/src/util/connected-provider.ts +15 -15
  315. package/src/util/delayed-presence.ts +34 -34
  316. package/src/util/diff.ts +84 -84
  317. package/src/util/error-details.ts +21 -21
  318. package/src/util/error.ts +141 -141
  319. package/src/util/filetype.ts +135 -135
  320. package/src/util/form.ts +146 -146
  321. package/src/util/highlights.ts +51 -51
  322. package/src/util/locale.ts +81 -81
  323. package/src/util/marquee.ts +51 -51
  324. package/src/util/media.ts +43 -43
  325. package/src/util/model.ts +33 -33
  326. package/src/util/path-format.ts +37 -37
  327. package/src/util/path.ts +12 -12
  328. package/src/util/permission.ts +188 -188
  329. package/src/util/persistence.ts +42 -42
  330. package/src/util/presentation.ts +42 -42
  331. package/src/util/project.ts +7 -7
  332. package/src/util/record.ts +3 -3
  333. package/src/util/renderer.ts +15 -15
  334. package/src/util/scroll.ts +29 -29
  335. package/src/util/selection.ts +103 -103
  336. package/src/util/session.ts +103 -103
  337. package/src/util/signal.ts +49 -49
  338. package/src/util/single-flight.ts +12 -12
  339. package/src/util/string-width.bun.ts +1 -1
  340. package/src/util/string-width.node.ts +26 -26
  341. package/src/util/string-width.ts +1 -1
  342. package/src/util/system.ts +23 -23
  343. package/src/util/todo.ts +43 -43
  344. package/src/util/tool-display.ts +70 -70
  345. package/src/util/usage-limits.ts +152 -152
  346. package/src/util/watch.ts +24 -24
  347. package/test/app-lifecycle.test.tsx +2962 -2962
  348. package/test/clear-session.test.tsx +67 -67
  349. package/test/cli/tui/__snapshots__/inline-tool-wrap-snapshot.test.tsx.snap +22 -22
  350. package/test/cli/tui/command-palette.test.tsx +86 -86
  351. package/test/cli/tui/composer-keymap.test.tsx +346 -346
  352. package/test/cli/tui/data.test.tsx +3669 -3669
  353. package/test/cli/tui/dialog-integration.test.tsx +588 -588
  354. package/test/cli/tui/dialog-mcp.test.tsx +197 -197
  355. package/test/cli/tui/dialog-open.test.tsx +1037 -1037
  356. package/test/cli/tui/dialog-prompt.test.tsx +253 -253
  357. package/test/cli/tui/dialog-select.test.tsx +740 -740
  358. package/test/cli/tui/dialog-session-list.test.tsx +130 -130
  359. package/test/cli/tui/diff-viewer-file-tree.test.tsx +256 -256
  360. package/test/cli/tui/diff-viewer-image.test.tsx +172 -172
  361. package/test/cli/tui/diff-viewer.test.tsx +2510 -2510
  362. package/test/cli/tui/form.test.tsx +950 -950
  363. package/test/cli/tui/group-view.test.tsx +352 -352
  364. package/test/cli/tui/inline-tool-wrap-snapshot.test.tsx +248 -248
  365. package/test/cli/tui/input-scope.test.tsx +282 -282
  366. package/test/cli/tui/keymap-arguments.test.tsx +45 -45
  367. package/test/cli/tui/plugins-dialog.test.tsx +217 -217
  368. package/test/cli/tui/prompt-interrupt-status.test.tsx +25 -25
  369. package/test/cli/tui/prompt-move.test.tsx +446 -446
  370. package/test/cli/tui/reasoning-body.test.tsx +80 -80
  371. package/test/cli/tui/theme-mode.test.tsx +179 -179
  372. package/test/cli/tui/toast.test.tsx +117 -117
  373. package/test/cli/tui/use-event.test.tsx +295 -295
  374. package/test/client-mcp.test.tsx +226 -226
  375. package/test/command-selection.test.tsx +123 -123
  376. package/test/compact-admission.test.tsx +251 -251
  377. package/test/completion-notices.test.tsx +197 -197
  378. package/test/component/animation-ticks.test.tsx +212 -212
  379. package/test/component/dialog-error-details.test.tsx +110 -110
  380. package/test/component/dialog-export-options.test.tsx +68 -68
  381. package/test/component/dialog-highlights.test.tsx +73 -73
  382. package/test/component/dialog-model.test.tsx +145 -145
  383. package/test/component/dialog-shell-output.test.tsx +255 -255
  384. package/test/component/dialog-speed.test.tsx +114 -114
  385. package/test/component/dialog-update.test.tsx +111 -111
  386. package/test/component/dialog-variant.test.tsx +24 -24
  387. package/test/component/go-upsell-art.test.tsx +110 -110
  388. package/test/component/retry-provider.test.tsx +288 -288
  389. package/test/component/session-tabs-marquee.test.tsx +100 -100
  390. package/test/component/session-tabs-mouse.test.tsx +216 -216
  391. package/test/component/session-tabs-rail.test.tsx +120 -120
  392. package/test/component/session-tabs-status.test.tsx +345 -345
  393. package/test/component/shimmer-text.test.tsx +37 -37
  394. package/test/component/spinner-renderable.test.tsx +133 -133
  395. package/test/component/tab-pulse.test.tsx +196 -196
  396. package/test/config-v2.test.tsx +335 -335
  397. package/test/config.test.tsx +184 -184
  398. package/test/context/local-selection.test.tsx +204 -204
  399. package/test/context/session-tabs.test.tsx +864 -864
  400. package/test/context/theme.test.tsx +183 -183
  401. package/test/copy-session-id.test.tsx +79 -79
  402. package/test/feature-plugins/goal.test.tsx +126 -126
  403. package/test/feature-plugins/prompt-footer.test.tsx +303 -303
  404. package/test/feature-plugins/sidebar-context.test.tsx +70 -70
  405. package/test/feature-plugins/sidebar-footer.test.tsx +139 -139
  406. package/test/fixture/animation-ticks.ts +19 -19
  407. package/test/fixture/app.ts +95 -95
  408. package/test/fixture/diff-image.ts +7 -7
  409. package/test/fixture/fixture.ts +27 -27
  410. package/test/fixture/frame.ts +25 -25
  411. package/test/fixture/local.tsx +158 -158
  412. package/test/fixture/plugin/client-reads/tui.tsx +9 -9
  413. package/test/fixture/plugin/dialog-throw/tui.tsx +11 -11
  414. package/test/fixture/plugin/native-resources/tui.tsx +26 -26
  415. package/test/fixture/plugin/setup-keymap/tui.tsx +72 -72
  416. package/test/fixture/plugin/slot-string/tui.tsx +10 -10
  417. package/test/fixture/tui-client.ts +186 -186
  418. package/test/fixture/tui-environment.tsx +47 -47
  419. package/test/fixture/tui-runtime.ts +21 -21
  420. package/test/interactivity.test.tsx +46 -46
  421. package/test/keymap-scope.test.tsx +271 -271
  422. package/test/keymap.test.tsx +244 -244
  423. package/test/markdown-streaming.test.tsx +49 -49
  424. package/test/mini/blocker.responsive.test.tsx +732 -732
  425. package/test/mini/fixture/catalog.ts +63 -63
  426. package/test/mini/fixture/footer-api.ts +69 -69
  427. package/test/mini/fixture/tool-part.ts +20 -20
  428. package/test/mini/footer-keymap.test.tsx +141 -141
  429. package/test/mini/footer.responsive.test.tsx +438 -438
  430. package/test/mini/footer.view.test.tsx +2627 -2627
  431. package/test/new-session-id.test.tsx +102 -102
  432. package/test/plugin-keymap.test.tsx +143 -143
  433. package/test/plugin-markdown.test.tsx +120 -120
  434. package/test/plugin-model.test.tsx +46 -46
  435. package/test/plugin-native-resources.test.tsx +11 -11
  436. package/test/plugin-select.test.tsx +391 -391
  437. package/test/plugin-slot-output.test.tsx +23 -23
  438. package/test/plugin-toast.test.tsx +62 -62
  439. package/test/preload.ts +17 -17
  440. package/test/prompt/history-composer.test.tsx +52 -52
  441. package/test/prompt/history-provider.test.tsx +108 -108
  442. package/test/prompt-cursor.test.tsx +27 -27
  443. package/test/prompt-offset.test.tsx +58 -58
  444. package/test/prompt-paste.test.tsx +127 -127
  445. package/test/prompt-shell-failure.test.tsx +76 -76
  446. package/test/routes/composer-tabs.test.tsx +97 -97
  447. package/test/runtime.test.tsx +37 -37
  448. package/test/session-activity-anchor.test.tsx +180 -180
  449. package/test/session-backfill-disclosure.test.tsx +89 -89
  450. package/test/session-dialog-resync.test.tsx +122 -122
  451. package/test/session-fork-pending.test.tsx +60 -60
  452. package/test/session-group-navigation.test.tsx +252 -252
  453. package/test/session-history-interactions.test.tsx +305 -305
  454. package/test/session-history-reveal.test.tsx +108 -108
  455. package/test/session-home.test.tsx +401 -401
  456. package/test/session-interrupt-undo.test.tsx +98 -98
  457. package/test/session-media-refs.test.tsx +360 -360
  458. package/test/session-mount-budget.test.tsx +137 -137
  459. package/test/session-panel.test.tsx +721 -721
  460. package/test/session-shell-output.test.tsx +114 -114
  461. package/test/session-shell-stopped.test.tsx +107 -107
  462. package/test/session-subagent-navigation.test.tsx +44 -44
  463. package/test/session-submit-scroll.test.tsx +85 -85
  464. package/test/session-terminal-availability.test.tsx +80 -80
  465. package/test/session-wheel-focus.test.tsx +176 -176
  466. package/test/stats.view.test.tsx +94 -94
  467. package/test/theme/v2/types.typecheck.ts +57 -57
  468. package/test/ui/dialog-layout.test.tsx +56 -56
  469. package/test/ui/link.test.tsx +60 -60
  470. package/test/ui/pane-resize-handle.test.tsx +134 -134
  471. package/test/ui/session-link.test.tsx +325 -325
  472. package/test/usage-limits.test.tsx +162 -162
  473. package/test/util/selection-copy-on-select.test.tsx +64 -64
  474. package/tsconfig.json +13 -13
  475. package/test/cli/cmd/tui/integration-options.test.ts +0 -98
  476. package/test/cli/cmd/tui/model-options.test.ts +0 -105
  477. package/test/cli/cmd/tui/notifications.test.ts +0 -356
  478. package/test/cli/tui/anchors.test.ts +0 -77
  479. package/test/cli/tui/collapse-tool-output.test.ts +0 -14
  480. package/test/cli/tui/group-boundary.test.ts +0 -63
  481. package/test/cli/tui/grouping-tree.test.ts +0 -82
  482. package/test/cli/tui/message-navigation.test.ts +0 -164
  483. package/test/cli/tui/mount-budget.test.ts +0 -74
  484. package/test/cli/tui/permission.test.ts +0 -7
  485. package/test/cli/tui/script-changes.test.ts +0 -41
  486. package/test/cli/tui/session-grouping.test.ts +0 -21
  487. package/test/cli/tui/session-history.test.ts +0 -124
  488. package/test/cli/tui/session-rows.test.ts +0 -616
  489. package/test/cli/tui/session-verbosity.test.ts +0 -307
  490. package/test/cli/tui/thinking.test.ts +0 -36
  491. package/test/clipboard.test.ts +0 -148
  492. package/test/component/terminal-pane-theme.test.ts +0 -68
  493. package/test/context/local.test.ts +0 -15
  494. package/test/context/program-status.test.ts +0 -73
  495. package/test/context/session-retention.test.ts +0 -234
  496. package/test/context/session-tabs-model.test.ts +0 -341
  497. package/test/context/storage.test.ts +0 -37
  498. package/test/editor.test.ts +0 -69
  499. package/test/feature-plugins/diff-viewer-file-tree-utils.test.ts +0 -234
  500. package/test/feature-plugins/home-footer.test.ts +0 -13
  501. package/test/highlights.test.ts +0 -43
  502. package/test/keybind.test.ts +0 -7
  503. package/test/mini/catalog.shared.test.ts +0 -76
  504. package/test/mini/entry.body.test.ts +0 -622
  505. package/test/mini/footer.menu.test.ts +0 -43
  506. package/test/mini/footer.test.ts +0 -446
  507. package/test/mini/footer.width.test.ts +0 -120
  508. package/test/mini/form.shared.test.ts +0 -66
  509. package/test/mini/permission.shared.test.ts +0 -195
  510. package/test/mini/prompt.editor.test.ts +0 -118
  511. package/test/mini/prompt.shared.test.ts +0 -104
  512. package/test/mini/runtime.boot.test.ts +0 -118
  513. package/test/mini/runtime.queue.test.ts +0 -443
  514. package/test/mini/runtime.test.ts +0 -591
  515. package/test/mini/scrollback.image.test.ts +0 -213
  516. package/test/mini/scrollback.surface.test.ts +0 -1078
  517. package/test/mini/session.shared.test.ts +0 -267
  518. package/test/mini/splash.test.ts +0 -196
  519. package/test/mini/stream-v2.transport.test.ts +0 -4705
  520. package/test/mini/stream.test.ts +0 -52
  521. package/test/mini/theme.test.ts +0 -438
  522. package/test/mini/tool.test.ts +0 -134
  523. package/test/mini/variant.shared.test.ts +0 -58
  524. package/test/mini/verbosity.test.ts +0 -53
  525. package/test/model-preference.test.ts +0 -70
  526. package/test/new-session-location.test.ts +0 -30
  527. package/test/panel.test.ts +0 -71
  528. package/test/plugin-discovery.test.ts +0 -18
  529. package/test/plugin-source.test.ts +0 -871
  530. package/test/prompt/attachment.test.ts +0 -138
  531. package/test/prompt/autocomplete.test.ts +0 -218
  532. package/test/prompt/codec.test.ts +0 -136
  533. package/test/prompt/display.test.ts +0 -72
  534. package/test/prompt/draft-stash.test.ts +0 -42
  535. package/test/prompt/history.test.ts +0 -94
  536. package/test/prompt/jsonl.test.ts +0 -24
  537. package/test/prompt/local-attachment.test.ts +0 -244
  538. package/test/prompt/mention.test.ts +0 -119
  539. package/test/prompt/parse.test.ts +0 -46
  540. package/test/prompt/part.test.ts +0 -40
  541. package/test/prompt/persistence.test.ts +0 -23
  542. package/test/prompt/traits.test.ts +0 -25
  543. package/test/simulation/semantics.test.ts +0 -23
  544. package/test/stats.test.ts +0 -33
  545. package/test/theme/v2/component.test.ts +0 -87
  546. package/test/theme/v2/resolve.test.ts +0 -424
  547. package/test/theme/v2/select.test.ts +0 -25
  548. package/test/theme/v2/v1-migrate.test.ts +0 -397
  549. package/test/theme.test.ts +0 -150
  550. package/test/ui/file-path.test.ts +0 -61
  551. package/test/ui/layout.test.ts +0 -31
  552. package/test/ui/pane-resize.test.ts +0 -258
  553. package/test/ui/select-controller.test.ts +0 -44
  554. package/test/util/added-patch.test.ts +0 -44
  555. package/test/util/connected-provider.test.ts +0 -59
  556. package/test/util/delayed-presence.test.ts +0 -114
  557. package/test/util/error-details.test.ts +0 -26
  558. package/test/util/error.test.ts +0 -36
  559. package/test/util/filetype.test.ts +0 -23
  560. package/test/util/form.test.ts +0 -110
  561. package/test/util/locale.test.ts +0 -32
  562. package/test/util/marquee.test.ts +0 -45
  563. package/test/util/media.test.ts +0 -54
  564. package/test/util/model.test.ts +0 -70
  565. package/test/util/path-format.test.ts +0 -15
  566. package/test/util/permission.test.ts +0 -23
  567. package/test/util/presentation.test.ts +0 -30
  568. package/test/util/renderer.test.ts +0 -42
  569. package/test/util/selection-keys.test.ts +0 -172
  570. package/test/util/selection.test.ts +0 -115
  571. package/test/util/session.test.ts +0 -70
  572. package/test/util/tool-display.test.ts +0 -65
  573. package/test/util/usage-limits.test.ts +0 -154
@@ -1,1380 +1,1380 @@
1
- /** @jsxImportSource @opentui/solid */
2
- import type { FileDiffInfo, LocationRef } from "@zyro-sec/client"
3
- import type { Vcs } from "@zyro-sec/schema/vcs"
4
- import { Plugin } from "@zyro-sec/plugin/tui"
5
- import type { KeymapCommand, PanelInput, Route } from "@zyro-sec/plugin/tui/context"
6
- import {
7
- MouseButton,
8
- TextAttributes,
9
- type BoxRenderable,
10
- type RGBA,
11
- type MouseEvent,
12
- type ScrollBoxRenderable,
13
- } from "@opentui/core"
14
- import { filetype } from "../../util/filetype"
15
- import { useRenderer, useTerminalDimensions } from "@opentui/solid"
16
- import { createEffect, createMemo, createResource, createSignal, For, Match, onCleanup, Show, Switch } from "solid-js"
17
- import { DiffViewerFileTree } from "./diff-viewer-file-tree"
18
- import { DiffFileMenu } from "./diff-viewer-file-menu"
19
- import { DiffViewerImage, isDiffImageFile } from "./diff-viewer-image"
20
- import { DIALOG_LIST_INSET, DialogHeader, DialogLayout } from "../../ui/dialog"
21
- import { DialogSelect } from "../../ui/dialog-select"
22
- import { EmptyBorder } from "../../ui/border"
23
- import { SESSION_PANEL_SPLIT_MIN_WIDTH } from "../../ui/layout"
24
- import { FilePath } from "../../ui/file-path"
25
- import { getScrollAcceleration } from "../../util/scroll"
26
- import { createDebouncedSignal } from "../../util/signal"
27
- import { type DiffSource, useConfig } from "../../config"
28
- import { locationKey } from "../../context/data"
29
- import { useTheme, useThemes } from "../../context/theme"
30
- import { PatchDiff, type PatchDiffRef } from "../../component/patch-diff"
31
- import {
32
- allExpandedFileTreeDirectories,
33
- buildFileTree,
34
- fileTreeFileSelection,
35
- type FileTreeRow,
36
- flattenFileTree,
37
- movePatchFileIndex,
38
- orderedPatchFileIndexes,
39
- showDiffViewerFileTree,
40
- singlePatchFileIndex,
41
- toggleFileTreeDirectory,
42
- } from "./diff-viewer-file-tree-utils"
43
-
44
- const ROUTE = "diff"
45
- const MIN_SPLIT_WIDTH = 100
46
- const FILE_TREE_MIN_WIDTH = 30
47
- const FILE_TREE_MAX_WIDTH = 40
48
- const FULL_INSET = 2
49
- // The full layout keeps its file tree and inset cards only while its patches stay as wide as the narrowest docked
50
- // panel, an equal split at the host's split threshold. Narrower full screens use the compact panel layout.
51
- const FULL_LAYOUT_MIN_WIDTH = FILE_TREE_MIN_WIDTH + FULL_INSET * 2 + Math.floor(SESSION_PANEL_SPLIT_MIN_WIDTH / 2)
52
- const FILE_HEADER_HEIGHT = 2
53
- const VCS_DIFF_CONTEXT_LINES = 12
54
- type DiffMode = DiffSource
55
- type DiffView = "split" | "unified"
56
- type SelectedHunk = { readonly fileIndex: number; readonly hunkIndex: number; readonly scrollTop: number }
57
- type FileMenuState = { readonly fileIndex: number; readonly x: number; readonly y: number }
58
-
59
- export type DiffFile = {
60
- readonly file: string
61
- readonly patch?: string
62
- readonly additions: number
63
- readonly deletions: number
64
- readonly status: "added" | "deleted" | "modified"
65
- }
66
-
67
- const normalizeDiffs = (diffs: readonly FileDiffInfo[]): DiffFile[] =>
68
- diffs.map((item) => ({
69
- file: item.file,
70
- patch: item.patch,
71
- additions: item.additions,
72
- deletions: item.deletions,
73
- status: item.status,
74
- }))
75
-
76
- function storedView(value: unknown): DiffView | undefined {
77
- if (value === "split" || value === "unified") return value
78
- }
79
-
80
- const DIFF_SOURCES = {
81
- branch: { label: "All", description: "Branch + local changes" },
82
- committed: { label: "Committed", description: "Branch commits only" },
83
- working: { label: "Uncommitted", description: "Local changes only" },
84
- turn: { label: "Last turn", description: "Latest session turn" },
85
- } satisfies Record<DiffMode, { label: string; description: string }>
86
-
87
- const VCS_SOURCES = ["branch", "committed", "working"] as const
88
-
89
- const needsBase = (mode: DiffMode) => mode === "branch" || mode === "committed"
90
-
91
- function DiffViewer(props: {
92
- context: Plugin.Context
93
- sessionID?: string
94
- initialMode?: DiffMode
95
- panel?: PanelInput
96
- onClose: () => void
97
- }) {
98
- const config = useConfig()
99
- const [memory, updateMemory] = props.context.storage.memory<{
100
- source?: DiffMode
101
- bases: Record<string, string>
102
- }>("review", { initial: { bases: {} } })
103
- const sessionID = () => props.sessionID
104
- const sources = (): readonly DiffMode[] => (sessionID() ? [...VCS_SOURCES, "turn"] : VCS_SOURCES)
105
- const initialMode = props.initialMode ?? memory.source ?? config.data.diffs?.source ?? "branch"
106
- const [mode, setMode] = createSignal(sources().includes(initialMode) ? initialMode : "branch")
107
- const location = createMemo(
108
- () => {
109
- const id = sessionID()
110
- return id
111
- ? (props.context.data.session.get(id)?.location ?? props.context.data.location.default())
112
- : props.context.data.location.default()
113
- },
114
- undefined,
115
- { equals: (a, b) => a.directory === b.directory },
116
- )
117
- const baseKey = createMemo(() =>
118
- JSON.stringify([locationKey(location()), props.context.data.location.vcs.info(location())?.branch.current]),
119
- )
120
- const selectedBase = () => memory.bases[baseKey()]
121
- // Mode changes share the same lazy base lookup until this viewer is closed.
122
- const bases = new Map<string, ReturnType<Plugin.Context["client"]["vcs"]["base"]>>()
123
- const [reportedBases, setReportedBases] = createSignal<ReadonlyMap<string, Vcs.Base | null>>(new Map())
124
- const loadBase = (location: LocationRef, key: string) => {
125
- const cached = bases.get(key)
126
- if (cached) return cached
127
- const pending = props.context.client.vcs.base({ location }).then((result) => {
128
- setReportedBases((known) => new Map(known).set(key, result.data))
129
- return result
130
- })
131
- bases.set(key, pending)
132
- return pending
133
- }
134
- const diffInput = createMemo(() => {
135
- const current = mode()
136
- const id = sessionID()
137
- if (current === "turn" && id) return { mode: current, sessionID: id }
138
- const vcs = current === "turn" ? "branch" : current
139
- return {
140
- mode: vcs,
141
- location: location(),
142
- key: baseKey(),
143
- selected: needsBase(vcs) ? selectedBase() : undefined,
144
- }
145
- })
146
- const [diff, { refetch }] = createResource(diffInput, async (input) => {
147
- if (input.mode === "turn") {
148
- return {
149
- base: null,
150
- files: normalizeDiffs(
151
- await props.context.client.session.diff({ sessionID: input.sessionID, context: VCS_DIFF_CONTEXT_LINES }),
152
- ),
153
- }
154
- }
155
- const base = !needsBase(input.mode)
156
- ? undefined
157
- : input.selected
158
- ? { name: input.selected, ref: input.selected }
159
- : (await loadBase(input.location, input.key)).data
160
- if (input !== diffInput() || (input.mode === "committed" && !base)) {
161
- return { base: null, files: [] }
162
- }
163
- const result = await props.context.client.vcs.diff({
164
- location: input.location,
165
- mode: input.mode,
166
- ...(base ? { base: base.ref } : {}),
167
- context: VCS_DIFF_CONTEXT_LINES,
168
- })
169
- return { base, files: normalizeDiffs(result.data ?? []) }
170
- })
171
- // Each completed turn replaces the last one.
172
- createEffect((previous) => {
173
- if (mode() !== "turn") return undefined
174
- const id = sessionID()
175
- const status = id ? props.context.data.session.status(id) : undefined
176
- if (previous === "running" && status === "idle") void refetch()
177
- return status
178
- })
179
- const sourceBase = () => {
180
- const ref = selectedBase()
181
- return ref ? { name: ref, ref } : reportedBases().get(baseKey())
182
- }
183
- const result = () => (diff.error || diff.loading ? undefined : diff())
184
- const sourceDetail = () => {
185
- if (mode() === "turn") return diff.error ? "Diff unavailable" : undefined
186
- if (mode() === "working") return "vs HEAD"
187
- if (diff.error) return "Base or diff unavailable"
188
- if (!result()) return "Resolving diff…"
189
- const base = result()?.base
190
- if (!base) return "Base not reported"
191
- return `vs ${base.name}`
192
- }
193
- return (
194
- <DiffViewerContent
195
- context={props.context}
196
- files={result()?.files ?? []}
197
- loading={diff.loading}
198
- error={diff.error}
199
- mode={mode()}
200
- sources={sources()}
201
- sourceDetail={sourceDetail()}
202
- sourceBase={sourceBase()}
203
- unavailable={mode() === "committed" && !!result() && !result()?.base}
204
- preferences={config.data.diffs}
205
- panel={props.panel}
206
- loadImage={(file, signal) => props.context.client.file.read({ path: file, location: location() }, { signal })}
207
- onPreferencesChange={(value) => {
208
- void config
209
- .update((draft) => {
210
- draft.diffs = { ...draft.diffs, ...value }
211
- })
212
- .catch(() => {})
213
- }}
214
- onClose={props.onClose}
215
- onSwitchSource={(mode) => {
216
- updateMemory((draft) => {
217
- draft.source = mode
218
- })
219
- setMode(mode)
220
- }}
221
- onChooseBase={() => {
222
- const target = { ...location() }
223
- const key = baseKey()
224
- if (!memory.bases[key]) void loadBase(target, key).catch(() => {})
225
- props.context.ui.dialog.show(() => (
226
- <DiffBaseDialog
227
- context={props.context}
228
- location={target}
229
- current={memory.bases[key] ?? reportedBases().get(key)?.ref}
230
- onSelect={(ref) =>
231
- updateMemory((draft) => {
232
- draft.bases[key] = ref
233
- })
234
- }
235
- />
236
- ))
237
- }}
238
- />
239
- )
240
- }
241
-
242
- function DiffRoute(props: {
243
- context: Plugin.Context
244
- data?: { mode?: DiffMode; sessionID?: string; returnRoute?: Route }
245
- }) {
246
- const dimensions = useTerminalDimensions()
247
- return (
248
- <box position="absolute" zIndex={2500} left={0} top={0} width={dimensions().width} height={dimensions().height}>
249
- <DiffViewer
250
- context={props.context}
251
- sessionID={props.data?.sessionID}
252
- initialMode={props.data?.mode}
253
- onClose={() => props.context.ui.router.navigate(props.data?.returnRoute ?? { type: "home" })}
254
- />
255
- </box>
256
- )
257
- }
258
-
259
- function DiffBaseDialog(props: {
260
- context: Plugin.Context
261
- location: LocationRef
262
- current?: string
263
- onSelect: (ref: string) => void
264
- }) {
265
- const theme = props.context.theme.surface("dialog")
266
- const [search, setSearch] = createDebouncedSignal("", 150)
267
- const [branches] = createResource(search, (search) =>
268
- props.context.client.vcs.branch.list({ location: props.location, search, limit: 100 }),
269
- )
270
- const Empty = () => (
271
- <box paddingLeft={DIALOG_LIST_INSET} paddingRight={DIALOG_LIST_INSET}>
272
- <text fg={branches.error ? theme.text.feedback.error.base : theme.text.muted}>
273
- {branches.loading
274
- ? "Loading branches…"
275
- : branches.error
276
- ? "Could not load branches. Reopen the picker to try again."
277
- : "No branches found"}
278
- </text>
279
- </box>
280
- )
281
-
282
- return (
283
- <DialogSelect
284
- title="Base branch"
285
- placeholder="Search local and remote branches"
286
- skipFilter
287
- current={props.current?.replace(/^refs\/(heads|remotes)\//, "")}
288
- onFilter={setSearch}
289
- emptyView={<Empty />}
290
- noMatchView={<Empty />}
291
- footer={<text fg={theme.text.muted}>Remembered until the TUI exits</text>}
292
- options={(branches.loading || branches.error ? [] : (branches()?.data ?? [])).map((name) => ({
293
- title: name,
294
- value: name,
295
- onSelect() {
296
- props.onSelect(name)
297
- props.context.ui.dialog.clear()
298
- },
299
- }))}
300
- />
301
- )
302
- }
303
-
304
- type DiffPreferences = { tree?: boolean; single?: boolean; view?: "auto" | DiffView; fullscreen?: boolean }
305
-
306
- export function DiffViewerContent(props: {
307
- context: Plugin.Context
308
- files: readonly DiffFile[]
309
- loading?: boolean
310
- error?: unknown
311
- mode: DiffMode
312
- sources: readonly DiffMode[]
313
- sourceDetail?: string
314
- sourceBase?: Pick<Vcs.Base, "name" | "ref"> | null
315
- unavailable?: boolean
316
- loadImage?: (file: string, signal: AbortSignal) => Promise<Uint8Array>
317
- preferences?: DiffPreferences
318
- panel?: PanelInput
319
- onPreferencesChange?: (value: DiffPreferences) => void
320
- onClose: () => void
321
- onSwitchSource: (mode: DiffMode) => void
322
- onChooseBase?: () => void
323
- }) {
324
- const renderer = useRenderer()
325
- const dimensions = useTerminalDimensions()
326
- const config = useConfig()
327
- const dialog = props.context.ui.dialog
328
- const theme = useTheme()
329
- const currentSyntax = useThemes().currentSyntax
330
- const files = () => props.files
331
- const docked = () => props.panel?.presentation === "panel"
332
- const width = () => props.panel?.width ?? dimensions().width
333
- // Docked panels and narrow full screens share the compact layout: no file tree, flush cards, and a footer.
334
- const compact = () => docked() || width() < FULL_LAYOUT_MIN_WIDTH
335
- // Full screen has no pane beside it to focus, and is always the active input scope.
336
- const focused = () => !docked() || props.panel?.focused === true
337
- // The side panel sits on the slot's raised surface; full screen keeps the base background.
338
- const surface = () => (docked() ? theme.background.raised.base : theme.background.base)
339
- // Cards are inset from the pane edges; the gaps between them run edge to edge.
340
- const inset = () => (compact() ? 0 : FULL_INSET)
341
- const mode = () => props.mode
342
- const [fileTreeEnabled, setFileTreeEnabled] = createSignal(props.preferences?.tree ?? true)
343
- const showFileTree = createMemo(() => !compact() && showDiffViewerFileTree(fileTreeEnabled(), files().length))
344
- const [singlePatch, setSinglePatch] = createSignal(props.preferences?.single ?? false)
345
- const fileTreeWidth = createMemo(() =>
346
- Math.max(FILE_TREE_MIN_WIDTH, Math.min(FILE_TREE_MAX_WIDTH, Math.floor(width() / 4))),
347
- )
348
- const patchPaneWidth = createMemo(() => width() - (showFileTree() ? fileTreeWidth() : 0) - inset() * 2)
349
- const splitAvailable = createMemo(() => patchPaneWidth() >= MIN_SPLIT_WIDTH)
350
- const [viewOverride, setViewOverride] = createSignal<DiffView | undefined>(storedView(props.preferences?.view))
351
- const view = createMemo(() =>
352
- splitAvailable() ? (viewOverride() ?? storedView(props.preferences?.view) ?? "split") : "unified",
353
- )
354
- const fileTree = createMemo(() => buildFileTree(files()))
355
- const [expandedFileNodes, setExpandedFileNodes] = createSignal<ReadonlySet<number>>(new Set())
356
- const [selectedFileIndex, setSelectedFileIndex] = createSignal<number | undefined>()
357
- const [reviewedFileNames, setReviewedFileNames] = createSignal<ReadonlySet<string>>(new Set())
358
- const [exhaustedFileIndex, setExhaustedFileIndex] = createSignal<number | undefined>()
359
- const [fileMenu, setFileMenu] = createSignal<FileMenuState>()
360
- const patchScrollAcceleration = createMemo(() => getScrollAcceleration(config.data))
361
- const patchFileIndexes = createMemo(() => orderedPatchFileIndexes(flattenFileTree(fileTree())))
362
- const helpShortcut = () => props.context.keymap.shortcuts("diff.help")[0]
363
- let scroll: ScrollBoxRenderable | undefined
364
- const patchNodeByFileIndex = new Map<number, BoxRenderable>()
365
- const patchDiffByFileIndex = new Map<number, PatchDiffRef>()
366
- const [selectedHunk, setSelectedHunk] = createSignal<SelectedHunk | undefined>()
367
- const [pendingPatchScrollFileIndex, setPendingPatchScrollFileIndex] = createSignal<number | undefined>()
368
-
369
- createEffect(() => {
370
- setExpandedFileNodes(allExpandedFileTreeDirectories(fileTree()))
371
- setSelectedFileIndex(undefined)
372
- setSelectedHunk(undefined)
373
- setReviewedFileNames(new Set<string>())
374
- setExhaustedFileIndex(undefined)
375
- setFileMenu(undefined)
376
- })
377
-
378
- const clearPatchSelection = () => {
379
- setPendingPatchScrollFileIndex(undefined)
380
- setSelectedHunk(undefined)
381
- if (!singlePatch()) setSelectedFileIndex(undefined)
382
- }
383
-
384
- const scrollPage = (direction: -1 | 1, divisor: 1 | 2) => {
385
- clearPatchSelection()
386
- if (scroll) scroll.scrollBy(direction * Math.max(1, Math.floor(scroll.viewport.height / divisor)))
387
- }
388
-
389
- const scrollPatchNodeToTop = (patchNode: BoxRenderable, offset?: number) => {
390
- if (!scroll || patchNode.isDestroyed) return
391
- const contentY = patchNode.y - scroll.content.y
392
- // The fixed pane edge replaces the leading separator when jumping to a later file.
393
- scroll.scrollTo(contentY + (offset ?? (contentY > 0 ? 1 : 0)))
394
- }
395
-
396
- const revealFileTreeFile = (fileIndex: number) => {
397
- const selection = fileTreeFileSelection(fileTree(), fileIndex)
398
- if (!selection) return
399
- setExpandedFileNodes((expanded) => {
400
- if ([...selection.expandedNodes].every((node) => expanded.has(node))) return expanded
401
- const next = new Set(expanded)
402
- selection.expandedNodes.forEach((node) => next.add(node))
403
- return next
404
- })
405
- }
406
-
407
- const selectPatchFile = (fileIndex: number) => {
408
- setPendingPatchScrollFileIndex(undefined)
409
- setExhaustedFileIndex(undefined)
410
- revealFileTreeFile(fileIndex)
411
- setSelectedFileIndex(fileIndex)
412
- }
413
-
414
- const scrollToFileIndex = (fileIndex: number | undefined) => {
415
- if (fileIndex === undefined) return
416
- selectPatchFile(fileIndex)
417
- const patchNode = patchNodeByFileIndex.get(fileIndex)
418
- if (patchNode) scrollPatchNodeToTop(patchNode)
419
- }
420
-
421
- const jumpToFileIndex = (fileIndex: number | undefined) => {
422
- if (fileIndex === undefined) return
423
- setSelectedHunk(undefined)
424
- scrollToFileIndex(fileIndex)
425
- if (singlePatch()) scrollSinglePatchToTop()
426
- }
427
-
428
- const currentPatchFileIndex = () => {
429
- if (!scroll) return undefined
430
- const viewportContentY = scroll.scrollTop + 1
431
- const entries = patchFileIndexes()
432
- .map((fileIndex) => ({
433
- fileIndex,
434
- node: patchNodeByFileIndex.get(fileIndex),
435
- }))
436
- .filter((entry): entry is { fileIndex: number; node: BoxRenderable } => Boolean(entry.node))
437
- .map((entry) => ({
438
- ...entry,
439
- contentY: scroll!.scrollTop + entry.node.y - scroll!.viewport.y,
440
- }))
441
- .sort((left, right) => left.contentY - right.contentY)
442
- return entries.findLast((entry) => entry.contentY <= viewportContentY)?.fileIndex ?? entries[0]?.fileIndex
443
- }
444
-
445
- const jumpRelativePatchFile = (offset: number) => {
446
- setSelectedHunk(undefined)
447
- const next = movePatchFileIndex(patchFileIndexes(), selectedFileIndex() ?? currentPatchFileIndex(), offset)
448
- if (singlePatch()) {
449
- if (next === undefined) return
450
- selectPatchFile(next)
451
- scrollSinglePatchToTop()
452
- return
453
- }
454
- scrollToFileIndex(next)
455
- }
456
-
457
- const jumpRelativeHunk = (offset: -1 | 1) => {
458
- const patchScroll = scroll
459
- if (!patchScroll) return
460
- const hunks = visiblePatchFiles()
461
- .flatMap((entry) => {
462
- return (
463
- patchDiffByFileIndex
464
- .get(entry.fileIndex)
465
- ?.hunks()
466
- .map((node, hunkIndex) => ({
467
- fileIndex: entry.fileIndex,
468
- hunkIndex,
469
- contentY: patchScroll.scrollTop + node.y - patchScroll.viewport.y - (hunkIndex > 0 ? 1 : 0),
470
- })) ?? []
471
- )
472
- })
473
- .sort((left, right) => left.contentY - right.contentY)
474
- const selected = selectedHunk()
475
- const selectedIndex =
476
- selected?.scrollTop === patchScroll.scrollTop
477
- ? hunks.findIndex((hunk) => hunk.fileIndex === selected.fileIndex && hunk.hunkIndex === selected.hunkIndex)
478
- : -1
479
- const contentTop = patchScroll.scrollTop + FILE_HEADER_HEIGHT
480
- const next =
481
- selectedIndex !== -1
482
- ? hunks[selectedIndex + offset]
483
- : offset === 1
484
- ? hunks.find((hunk) => hunk.contentY > contentTop)
485
- : hunks.findLast((hunk) => hunk.contentY < contentTop)
486
- if (!next) return
487
- selectPatchFile(next.fileIndex)
488
- patchScroll.scrollTo(Math.max(0, next.contentY - FILE_HEADER_HEIGHT))
489
- setSelectedHunk({ fileIndex: next.fileIndex, hunkIndex: next.hunkIndex, scrollTop: patchScroll.scrollTop })
490
- }
491
-
492
- const firstPatchFileIndex = () => patchFileIndexes()[0]
493
- const visiblePatchFiles = createMemo(() => {
494
- if (!singlePatch()) {
495
- return patchFileIndexes().flatMap((fileIndex) => {
496
- const file = files()[fileIndex]
497
- return file ? [{ file, fileIndex }] : []
498
- })
499
- }
500
- const fileIndex = singlePatchFileIndex(selectedFileIndex(), currentPatchFileIndex(), firstPatchFileIndex())
501
- const file = fileIndex === undefined ? undefined : files()[fileIndex]
502
- return file && fileIndex !== undefined ? [{ file, fileIndex }] : []
503
- })
504
-
505
- const ensureHighlightedPatchFile = () => {
506
- const fileIndex = currentPatchFileIndex() ?? selectedFileIndex() ?? firstPatchFileIndex()
507
- if (fileIndex === undefined) return
508
- selectPatchFile(fileIndex)
509
- }
510
-
511
- const scrollToPatchFileIndexAfterRender = (fileIndex: number, offset?: number) => {
512
- setPendingPatchScrollFileIndex(fileIndex)
513
- renderer.requestAnimationFrame(() => {
514
- if (pendingPatchScrollFileIndex() !== fileIndex) return
515
- const patchNode = patchNodeByFileIndex.get(fileIndex)
516
- if (patchNode) scrollPatchNodeToTop(patchNode, offset)
517
- renderer.requestAnimationFrame(() => {
518
- if (pendingPatchScrollFileIndex() !== fileIndex) return
519
- const patchNode = patchNodeByFileIndex.get(fileIndex)
520
- if (patchNode) scrollPatchNodeToTop(patchNode, offset)
521
- setPendingPatchScrollFileIndex(undefined)
522
- })
523
- })
524
- }
525
-
526
- const scrollSinglePatchToTop = () => {
527
- renderer.requestAnimationFrame(() => {
528
- scroll?.scrollTo(0)
529
- renderer.requestAnimationFrame(() => scroll?.scrollTo(0))
530
- })
531
- }
532
-
533
- const registerPatchNode = (fileIndex: number, element: BoxRenderable) => {
534
- patchNodeByFileIndex.set(fileIndex, element)
535
- if (pendingPatchScrollFileIndex() !== fileIndex) return
536
- scrollToPatchFileIndexAfterRender(fileIndex)
537
- }
538
-
539
- const clickFileTreeRow = (row: FileTreeRow) => {
540
- if (row.fileIndex !== undefined) {
541
- jumpToFileIndex(row.fileIndex)
542
- return
543
- }
544
- setExpandedFileNodes((expanded) => toggleFileTreeDirectory(fileTree(), expanded, row.id))
545
- }
546
-
547
- const toggleFileReviewed = (fileIndex: number | undefined) => {
548
- if (fileIndex === undefined) return
549
- const file = files()[fileIndex]?.file
550
- if (!file) return
551
- const current = selectedFileIndex() ?? currentPatchFileIndex()
552
- const anchor = current === undefined ? undefined : patchNodeByFileIndex.get(current)
553
- const offset = anchor && scroll ? scroll.viewport.y - anchor.y : undefined
554
- const reviewed = reviewedFileNames().has(file)
555
- setReviewedFileNames((reviewed) => {
556
- const next = new Set(reviewed)
557
- if (next.has(file)) next.delete(file)
558
- else next.add(file)
559
- return next
560
- })
561
- // Completing another file from its menu must not navigate away from the current file.
562
- if (fileIndex !== current) {
563
- if (current !== undefined && offset !== undefined && !singlePatch())
564
- scrollToPatchFileIndexAfterRender(current, offset)
565
- return
566
- }
567
- const nextFileIndex =
568
- singlePatch() && !reviewed ? (movePatchFileIndex(patchFileIndexes(), fileIndex, 1) ?? fileIndex) : fileIndex
569
- selectPatchFile(nextFileIndex)
570
- if (singlePatch() && !reviewed && nextFileIndex === fileIndex) setExhaustedFileIndex(fileIndex)
571
- setSelectedHunk(undefined)
572
- scrollToPatchFileIndexAfterRender(nextFileIndex)
573
- }
574
-
575
- const openFileMenu = (fileIndex: number, event: MouseEvent) => {
576
- if (event.button !== MouseButton.RIGHT) return
577
- event.preventDefault()
578
- event.stopPropagation()
579
- props.panel?.focus()
580
- setFileMenu({ fileIndex, x: event.x, y: event.y })
581
- }
582
-
583
- const close = () => {
584
- dialog.clear()
585
- props.onClose()
586
- }
587
-
588
- const commands: KeymapCommand[] = [
589
- {
590
- id: "diff.close",
591
- title: "Close diff viewer",
592
- group: "VCS",
593
- run: close,
594
- },
595
- {
596
- id: "diff.down",
597
- title: "Move diff viewer down",
598
- group: "VCS",
599
- run() {
600
- clearPatchSelection()
601
- scroll?.scrollBy(1)
602
- },
603
- },
604
- {
605
- id: "diff.up",
606
- title: "Move diff viewer up",
607
- group: "VCS",
608
- run() {
609
- clearPatchSelection()
610
- scroll?.scrollBy(-1)
611
- },
612
- },
613
- {
614
- id: "diff.page.down",
615
- title: "Page diff viewer down",
616
- group: "VCS",
617
- run: () => scrollPage(1, 1),
618
- },
619
- {
620
- id: "diff.page.up",
621
- title: "Page diff viewer up",
622
- group: "VCS",
623
- run: () => scrollPage(-1, 1),
624
- },
625
- {
626
- id: "diff.half_page.down",
627
- title: "Scroll down half a page",
628
- group: "VCS",
629
- run: () => scrollPage(1, 2),
630
- },
631
- {
632
- id: "diff.half_page.up",
633
- title: "Scroll up half a page",
634
- group: "VCS",
635
- run: () => scrollPage(-1, 2),
636
- },
637
- {
638
- id: "diff.first",
639
- title: "Go to the start of the diff",
640
- group: "VCS",
641
- run() {
642
- clearPatchSelection()
643
- scroll?.scrollTo(0)
644
- },
645
- },
646
- {
647
- id: "diff.last",
648
- title: "Go to the end of the diff",
649
- group: "VCS",
650
- run() {
651
- clearPatchSelection()
652
- if (scroll) scroll.scrollTo(scroll.scrollHeight)
653
- },
654
- },
655
- {
656
- id: "diff.next_hunk",
657
- title: "Jump to next diff hunk",
658
- group: "VCS",
659
- run() {
660
- jumpRelativeHunk(1)
661
- },
662
- },
663
- {
664
- id: "diff.previous_hunk",
665
- title: "Jump to previous diff hunk",
666
- group: "VCS",
667
- run() {
668
- jumpRelativeHunk(-1)
669
- },
670
- },
671
- {
672
- id: "diff.next_file",
673
- title: "Jump to next diff file",
674
- group: "VCS",
675
- run() {
676
- jumpRelativePatchFile(1)
677
- },
678
- },
679
- {
680
- id: "diff.previous_file",
681
- title: "Jump to previous diff file",
682
- group: "VCS",
683
- run() {
684
- jumpRelativePatchFile(-1)
685
- },
686
- },
687
- {
688
- id: "diff.mark_reviewed",
689
- title: "Toggle selected diff file reviewed",
690
- group: "VCS",
691
- run() {
692
- const fileIndex = selectedFileIndex() ?? currentPatchFileIndex()
693
- if (fileIndex !== undefined && fileIndex === exhaustedFileIndex()) return
694
- toggleFileReviewed(fileIndex)
695
- },
696
- },
697
- {
698
- id: "diff.toggle_file_tree",
699
- title: "Toggle diff viewer file tree",
700
- group: "VCS",
701
- enabled: () => !compact(),
702
- run() {
703
- if (compact()) return
704
- const next = !fileTreeEnabled()
705
- setFileTreeEnabled(next)
706
- props.onPreferencesChange?.({ tree: next })
707
- },
708
- },
709
- {
710
- id: "diff.single_patch",
711
- title: "Toggle single patch view",
712
- group: "VCS",
713
- run() {
714
- setSelectedHunk(undefined)
715
- if (!singlePatch()) {
716
- ensureHighlightedPatchFile()
717
- setSinglePatch(true)
718
- props.onPreferencesChange?.({ single: true })
719
- scrollSinglePatchToTop()
720
- return
721
- }
722
- const fileIndex =
723
- visiblePatchFiles()[0]?.fileIndex ??
724
- singlePatchFileIndex(selectedFileIndex(), currentPatchFileIndex(), firstPatchFileIndex())
725
- if (fileIndex !== undefined) selectPatchFile(fileIndex)
726
- setSinglePatch(false)
727
- props.onPreferencesChange?.({ single: false })
728
- if (fileIndex !== undefined) scrollToPatchFileIndexAfterRender(fileIndex)
729
- },
730
- },
731
- {
732
- id: "diff.switch_source",
733
- title: "Switch diff viewer source",
734
- group: "VCS",
735
- run() {
736
- openSwitchDiffDialog()
737
- },
738
- },
739
- {
740
- id: "diff.toggle_view",
741
- title: "Toggle diff viewer split or unified view",
742
- group: "VCS",
743
- run() {
744
- if (!splitAvailable()) return
745
- setSelectedHunk(undefined)
746
- const next = view() === "split" ? "unified" : "split"
747
- setViewOverride(next)
748
- props.onPreferencesChange?.({ view: next })
749
- },
750
- },
751
- {
752
- id: "diff.toggle_fullscreen",
753
- title: "Toggle diff viewer full screen",
754
- group: "VCS",
755
- enabled: () => props.panel !== undefined,
756
- run: () => {
757
- const panel = props.panel
758
- if (!panel) return
759
- const before = panel.presentation
760
- panel.toggleFullscreen()
761
- // A narrow terminal forces full screen and ignores the toggle; only a real toggle is remembered.
762
- if (panel.presentation === before) return
763
- props.onPreferencesChange?.({ fullscreen: panel.presentation === "fullscreen" })
764
- },
765
- },
766
- {
767
- id: "diff.help",
768
- title: "Show more diff viewer shortcuts",
769
- group: "VCS",
770
- run() {
771
- openHelpDialog()
772
- },
773
- },
774
- // Specific diff bindings take precedence over app.exit's Ctrl+D binding.
775
- {
776
- id: "app.exit",
777
- title: "Close diff viewer",
778
- group: "VCS",
779
- run: close,
780
- },
781
- ]
782
-
783
- const openSwitchDiffDialog = () => {
784
- dialog.show(() => (
785
- <DialogSelect<DiffMode | "base">
786
- title="Diff source"
787
- skipFilter={true}
788
- renderFilter={false}
789
- current={mode()}
790
- options={[
791
- ...props.sources.map((source) => ({
792
- value: source,
793
- title: DIFF_SOURCES[source].label,
794
- titleView: DIFF_SOURCES[source].label.padEnd(11),
795
- description: DIFF_SOURCES[source].description,
796
- onSelect() {
797
- dialog.clear()
798
- props.onSwitchSource(source)
799
- },
800
- })),
801
- ...(props.onChooseBase
802
- ? [
803
- {
804
- title: "Base",
805
- titleView: "Base".padEnd(11),
806
- value: "base" as const,
807
- description: props.sourceBase?.name ?? "Choose…",
808
- onSelect: props.onChooseBase,
809
- },
810
- ]
811
- : []),
812
- ]}
813
- />
814
- ))
815
- }
816
-
817
- const openHelpDialog = () => {
818
- dialog.show(() => (
819
- <DiffViewerHelpDialog
820
- context={props.context}
821
- single={singlePatch()}
822
- fullscreen={props.panel !== undefined}
823
- tree={!compact()}
824
- />
825
- ))
826
- dialog.set({ size: "medium", centered: true })
827
- }
828
-
829
- const HelpShortcut = (props: { compact?: boolean; label?: string; muted?: boolean }) => (
830
- <Show when={helpShortcut()}>
831
- {(shortcut) => (
832
- <text
833
- id="diff-help-shortcut"
834
- fg={props.muted ? theme.text.action.primary.disabled : theme.text.base}
835
- attributes={props.muted ? TextAttributes.DIM : 0}
836
- selectable={false}
837
- flexShrink={0}
838
- wrapMode="none"
839
- onMouseUp={(event) => {
840
- if (event.button !== MouseButton.LEFT) return
841
- event.stopPropagation()
842
- openHelpDialog()
843
- }}
844
- >
845
- {props.compact ? "?" : shortcut()}
846
- <Show when={!props.compact}>
847
- <span style={props.muted ? {} : { fg: theme.text.muted }}> {props.label ?? "help"}</span>
848
- </Show>
849
- </text>
850
- )}
851
- </Show>
852
- )
853
-
854
- props.context.keymap.layer(() => ({
855
- commands,
856
- }))
857
-
858
- return (
859
- <box width="100%" height="100%" backgroundColor={surface()}>
860
- <Show when={!showFileTree()}>
861
- <box
862
- id="diff-source-header"
863
- paddingLeft={2}
864
- // Compact, the header lines up with the card text below it; the card edge row supplies the gap underneath.
865
- paddingRight={compact() ? 1 : 2}
866
- // Only the docked panel leaves a row above the header; full screen starts at the top edge.
867
- paddingTop={docked() ? 1 : 0}
868
- height={docked() ? 2 : 1}
869
- flexShrink={0}
870
- flexDirection="row"
871
- gap={1}
872
- >
873
- <box
874
- id="diff-source-switch"
875
- flexDirection="row"
876
- flexGrow={1}
877
- minWidth={0}
878
- onMouseUp={(event) => {
879
- if (event.button !== MouseButton.LEFT) return
880
- event.stopPropagation()
881
- openSwitchDiffDialog()
882
- }}
883
- >
884
- <text
885
- fg={theme.text.action.secondary.base}
886
- attributes={TextAttributes.BOLD}
887
- selectable={false}
888
- flexShrink={0}
889
- wrapMode="none"
890
- >
891
- {DIFF_SOURCES[mode()].label}
892
- </text>
893
- <Show when={props.sourceDetail}>
894
- <text fg={theme.text.muted} selectable={false} flexGrow={1} minWidth={0} wrapMode="none" truncate>
895
- {` · ${props.sourceDetail}`}
896
- </text>
897
- </Show>
898
- </box>
899
- <text id="diff-review-count" fg={theme.text.muted} flexShrink={0} wrapMode="none">
900
- {files().filter((file) => reviewedFileNames().has(file.file)).length}/{files().length}
901
- </text>
902
- </box>
903
- </Show>
904
- <box flexGrow={1} minHeight={0}>
905
- <Switch>
906
- <Match when={props.loading}>
907
- <box flexGrow={1} padding={2} paddingTop={compact() ? 1 : 2}>
908
- <text fg={theme.text.muted}>Loading diff…</text>
909
- </box>
910
- </Match>
911
- <Match when={!props.loading && props.error}>
912
- <box flexGrow={1} padding={2} paddingTop={compact() ? 1 : 2}>
913
- <text fg={theme.text.feedback.error.base}>
914
- {!props.sourceBase && needsBase(mode())
915
- ? "Could not load diff. Choose a base branch from Diff source, or select Uncommitted."
916
- : "Could not load diff. Reopen the diff viewer to try again."}
917
- </text>
918
- </box>
919
- </Match>
920
- <Match when={!props.loading && props.unavailable}>
921
- <box flexGrow={1} padding={2} paddingTop={compact() ? 1 : 2}>
922
- <text fg={theme.text.muted}>
923
- Committed comparison unavailable without base metadata. Choose a base branch from Diff source.
924
- </text>
925
- </box>
926
- </Match>
927
- <Match when={!props.loading && files().length === 0}>
928
- <box flexGrow={1} padding={2} paddingTop={compact() ? 1 : 2}>
929
- <text fg={theme.text.muted}>No changes to show</text>
930
- </box>
931
- </Match>
932
- <Match when={!props.loading}>
933
- <box flexDirection="row" flexGrow={1} minHeight={0}>
934
- <Show when={showFileTree()}>
935
- <DiffViewerFileTree
936
- files={files()}
937
- loading={props.loading ?? false}
938
- error={props.error}
939
- width={fileTreeWidth()}
940
- selectedFileIndex={
941
- selectedFileIndex() ?? (singlePatch() ? visiblePatchFiles()[0]?.fileIndex : undefined)
942
- }
943
- reviewedFileNames={reviewedFileNames()}
944
- expandedNodes={expandedFileNodes()}
945
- onRowClick={clickFileTreeRow}
946
- onFileContextMenu={openFileMenu}
947
- source={DIFF_SOURCES[mode()].label}
948
- sourceDetail={props.sourceDetail}
949
- onSwitchSource={openSwitchDiffDialog}
950
- footer={<HelpShortcut />}
951
- />
952
- </Show>
953
-
954
- <box flexGrow={1} minWidth={0} minHeight={0}>
955
- <box
956
- id="diff-patch-top-edge"
957
- marginLeft={inset()}
958
- marginRight={inset()}
959
- ref={(edge: BoxRenderable) => {
960
- // The fixed edge belongs to the visible card, not the tree selection.
961
- edge.onLifecyclePass = () => {
962
- if (!scroll) return
963
- const entry = visiblePatchFiles().findLast(
964
- (entry) => (patchNodeByFileIndex.get(entry.fileIndex)?.y ?? Infinity) <= scroll!.viewport.y,
965
- )
966
- edge.backgroundColor =
967
- entry && reviewedFileNames().has(entry.file.file)
968
- ? theme.background.raised.high
969
- : theme.diff.background.context
970
- }
971
- renderer.registerLifecyclePass(edge)
972
- onCleanup(() => renderer.unregisterLifecyclePass(edge))
973
- }}
974
- height={1}
975
- flexShrink={0}
976
- backgroundColor={theme.diff.background.context}
977
- />
978
- <scrollbox
979
- id="diff-patches"
980
- ref={(element: ScrollBoxRenderable) => (scroll = element)}
981
- flexGrow={1}
982
- minHeight={0}
983
- scrollAcceleration={patchScrollAcceleration()}
984
- onMouseScroll={clearPatchSelection}
985
- verticalScrollbarOptions={{ visible: false }}
986
- horizontalScrollbarOptions={{ visible: false }}
987
- >
988
- <For each={visiblePatchFiles()}>
989
- {(entry, index) => {
990
- const reviewed = () => reviewedFileNames().has(entry.file.file)
991
- const background = () =>
992
- reviewed() ? theme.background.raised.high : theme.diff.background.context
993
- const image = () => isDiffImageFile(entry.file.file)
994
- const countsWidth = () =>
995
- (image() ? 6 : String(entry.file.additions).length + String(entry.file.deletions).length + 5) +
996
- (reviewed() ? 2 : 0)
997
- return (
998
- <box ref={(element: BoxRenderable) => registerPatchNode(entry.fileIndex, element)}>
999
- <Show when={index() > 0}>
1000
- <CardGap glyph="▄" card={background()} surface={surface()} inset={inset()} />
1001
- </Show>
1002
- <box backgroundColor={background()} marginLeft={inset()} marginRight={inset()}>
1003
- <box
1004
- id={`diff-file-header-${entry.fileIndex}`}
1005
- onMouseDown={(event) => openFileMenu(entry.fileIndex, event)}
1006
- ref={(header: BoxRenderable) => {
1007
- // Move the original title without changing flow, bounded by its own card.
1008
- header.onLifecyclePass = () => {
1009
- if (!scroll || !header.parent) return
1010
- header.translateY = Math.max(
1011
- 0,
1012
- Math.min(
1013
- scroll.scrollTop - (header.parent.y - scroll.content.y),
1014
- header.parent.height - header.height,
1015
- ),
1016
- )
1017
- }
1018
- renderer.registerLifecyclePass(header)
1019
- onCleanup(() => renderer.unregisterLifecyclePass(header))
1020
- }}
1021
- flexDirection="row"
1022
- gap={1}
1023
- flexShrink={0}
1024
- height={FILE_HEADER_HEIGHT}
1025
- zIndex={1}
1026
- backgroundColor={background()}
1027
- paddingLeft={compact() ? 2 : 1}
1028
- paddingRight={1}
1029
- paddingBottom={1}
1030
- >
1031
- <box flexGrow={1} minWidth={0}>
1032
- <FilePath
1033
- value={entry.file.file}
1034
- maxWidth={Math.max(1, patchPaneWidth() - countsWidth() - 2)}
1035
- fg={theme.text.muted}
1036
- basenameFg={reviewed() ? theme.text.muted : theme.text.base}
1037
- />
1038
- </box>
1039
- <Show when={reviewed()}>
1040
- <text fg={theme.text.muted} flexShrink={0}>
1041
- ✓
1042
- </text>
1043
- </Show>
1044
- <Show when={!image()} fallback={<text fg={theme.text.muted}>Image</text>}>
1045
- <text flexShrink={0} fg={reviewed() ? theme.text.muted : theme.diff.text.added}>
1046
- +{entry.file.additions}
1047
- </text>
1048
- <text flexShrink={0} fg={reviewed() ? theme.text.muted : theme.diff.text.removed}>
1049
- -{entry.file.deletions}
1050
- </text>
1051
- </Show>
1052
- <Show when={reviewed()}>
1053
- <box position="absolute" left={-inset()} right={-inset()} bottom={0} height={1}>
1054
- <CardGap glyph="▀" card={background()} surface={surface()} inset={inset()} />
1055
- </box>
1056
- </Show>
1057
- </box>
1058
- <Show when={!reviewed()}>
1059
- <Switch
1060
- fallback={
1061
- <box
1062
- width="100%"
1063
- flexShrink={0}
1064
- paddingLeft={compact() ? 2 : 1}
1065
- paddingRight={1}
1066
- paddingBottom={1}
1067
- >
1068
- <text fg={theme.text.muted}>
1069
- {mode() === "committed" && image()
1070
- ? "Committed image preview unavailable. The working-tree image is not shown."
1071
- : entry.file.status === "deleted" && image()
1072
- ? "Deleted image. The previous revision is not available for preview."
1073
- : "No patch available for this file."}
1074
- </text>
1075
- </box>
1076
- }
1077
- >
1078
- <Match
1079
- when={
1080
- mode() !== "committed" &&
1081
- entry.file.status !== "deleted" &&
1082
- image() &&
1083
- props.loadImage
1084
- }
1085
- >
1086
- {(load) => <DiffViewerImage file={entry.file.file} load={load()} />}
1087
- </Match>
1088
- <Match when={!(mode() === "committed" && image()) && entry.file.patch}>
1089
- {(patch) => (
1090
- <PatchDiff
1091
- ref={(component) => {
1092
- patchDiffByFileIndex.set(entry.fileIndex, component)
1093
- onCleanup(() => patchDiffByFileIndex.delete(entry.fileIndex))
1094
- }}
1095
- diff={patch()}
1096
- scroll={() => scroll}
1097
- hunkFg={theme.diff.text.hunkHeader}
1098
- view={entry.file.status === "modified" ? view() : "unified"}
1099
- filetype={filetype(entry.file.file)}
1100
- syntaxStyle={currentSyntax()}
1101
- showLineNumbers={true}
1102
- gutterPadding={compact() ? 1 : 0}
1103
- width="100%"
1104
- wrapMode="char"
1105
- fg={theme.text.base}
1106
- addedBg={theme.diff.background.added}
1107
- removedBg={theme.diff.background.removed}
1108
- contextBg={theme.diff.background.context}
1109
- addedSignColor={theme.diff.highlight.added}
1110
- removedSignColor={theme.diff.highlight.removed}
1111
- lineNumberFg={theme.diff.lineNumber.text}
1112
- lineNumberBg={theme.diff.background.context}
1113
- addedLineNumberBg={theme.diff.lineNumber.background.added}
1114
- removedLineNumberBg={theme.diff.lineNumber.background.removed}
1115
- />
1116
- )}
1117
- </Match>
1118
- </Switch>
1119
- </Show>
1120
- </box>
1121
- </box>
1122
- )
1123
- }}
1124
- </For>
1125
- </scrollbox>
1126
- </box>
1127
- </box>
1128
- </Match>
1129
- </Switch>
1130
- </box>
1131
- <Show when={compact()}>
1132
- {/* Docked, the footer sits on the terminal background, eased in by a half-cell like the prompt. */}
1133
- <box id="diff-footer" flexShrink={0} backgroundColor={theme.background.base}>
1134
- <Show when={docked()}>
1135
- <box
1136
- height={1}
1137
- flexShrink={0}
1138
- border={["bottom"]}
1139
- borderColor={surface()}
1140
- backgroundColor={theme.background.base}
1141
- customBorderChars={{ ...EmptyBorder, horizontal: "▀" }}
1142
- />
1143
- </Show>
1144
- <box height={1} flexShrink={0} flexDirection="row" paddingLeft={2} paddingRight={1}>
1145
- <text
1146
- fg={focused() ? theme.background.action.primary.focused : theme.text.action.primary.disabled}
1147
- attributes={focused() ? 0 : TextAttributes.DIM}
1148
- flexGrow={1}
1149
- minWidth={0}
1150
- wrapMode="none"
1151
- truncate
1152
- selectable={false}
1153
- onMouseUp={(event) => {
1154
- if (event.button !== MouseButton.LEFT) return
1155
- if (!docked()) return close()
1156
- if (!props.panel?.focused) props.panel?.focus()
1157
- }}
1158
- >
1159
- {/* Without a prompt beside the viewer, closing is the way back to the session. */}
1160
- <span>{props.context.keymap.shortcuts(docked() ? "pane.focus.left" : "diff.close")[0] ?? ""}</span>
1161
- <span style={focused() ? { fg: theme.text.muted } : {}}>{docked() ? " focus prompt" : " close"}</span>
1162
- </text>
1163
- <box flexShrink={0}>
1164
- <HelpShortcut label="see all" muted={!focused()} />
1165
- </box>
1166
- </box>
1167
- <Show when={docked()}>
1168
- <box height={1} flexShrink={0} />
1169
- </Show>
1170
- </box>
1171
- </Show>
1172
- <Show when={!showFileTree() && !compact()}>
1173
- <box position="absolute" top={0} right={0} width={1} height={1}>
1174
- <HelpShortcut compact />
1175
- </box>
1176
- </Show>
1177
- <Show when={fileMenu()} keyed>
1178
- {(state) => (
1179
- <DiffFileMenu
1180
- context={props.context}
1181
- state={state}
1182
- reviewed={reviewedFileNames().has(files()[state.fileIndex]?.file ?? "")}
1183
- onToggle={() => toggleFileReviewed(state.fileIndex)}
1184
- onClose={() => setFileMenu(undefined)}
1185
- />
1186
- )}
1187
- </Show>
1188
- </box>
1189
- )
1190
- }
1191
-
1192
- /** A half-row of base background between cards: the card's color over its width, the pane surface in the insets. */
1193
- function CardGap(props: { glyph: "▄" | "▀"; card: RGBA; surface: RGBA; inset: number }) {
1194
- const theme = useTheme()
1195
- const half = (color: RGBA, width?: number) => (
1196
- <box
1197
- height={1}
1198
- flexShrink={0}
1199
- {...(width === undefined ? { flexGrow: 1 } : { width })}
1200
- border={[props.glyph === "▄" ? "top" : "bottom"]}
1201
- borderColor={color}
1202
- backgroundColor={theme.background.base}
1203
- customBorderChars={{ ...EmptyBorder, horizontal: props.glyph }}
1204
- />
1205
- )
1206
- return (
1207
- <box height={1} flexShrink={0} flexDirection="row">
1208
- {/* A zero-width inset still claims a cell, which would notch flush cards. */}
1209
- <Show when={props.inset > 0}>{half(props.surface, props.inset)}</Show>
1210
- {half(props.card)}
1211
- <Show when={props.inset > 0}>{half(props.surface, props.inset)}</Show>
1212
- </box>
1213
- )
1214
- }
1215
-
1216
- function DiffViewerHelpDialog(props: { context: Plugin.Context; single: boolean; fullscreen: boolean; tree: boolean }) {
1217
- const dimensions = useTerminalDimensions()
1218
- const theme = props.context.theme.surface("dialog")
1219
- const shortcut =
1220
- (...ids: string[]) =>
1221
- () =>
1222
- ids
1223
- .map((id) => props.context.keymap.shortcuts(id)[0])
1224
- .filter(Boolean)
1225
- .join(" / ")
1226
- const groups = [
1227
- {
1228
- title: "Review",
1229
- rows: [
1230
- { shortcut: () => props.context.keymap.shortcuts("diff.next_file").join(" / "), label: "Next file" },
1231
- { shortcut: () => props.context.keymap.shortcuts("diff.previous_file").join(" / "), label: "Previous file" },
1232
- {
1233
- shortcut: shortcut("diff.mark_reviewed"),
1234
- label: props.single ? "Review + next / reopen" : "Review + collapse / reopen",
1235
- },
1236
- { shortcut: shortcut("diff.next_hunk", "diff.previous_hunk"), label: "Next / previous change" },
1237
- { shortcut: () => "right-click", label: "File menu (heading or tree)" },
1238
- ],
1239
- },
1240
- {
1241
- title: "Scroll",
1242
- rows: [
1243
- { shortcut: shortcut("diff.down", "diff.up"), label: "Down / up" },
1244
- { shortcut: shortcut("diff.half_page.down", "diff.half_page.up"), label: "Half page down / up" },
1245
- { shortcut: shortcut("diff.page.down", "diff.page.up"), label: "Page down / up" },
1246
- { shortcut: shortcut("diff.first", "diff.last"), label: "First / last" },
1247
- ],
1248
- },
1249
- {
1250
- title: "View",
1251
- rows: [
1252
- { shortcut: shortcut("diff.toggle_view"), label: "Split / unified" },
1253
- { shortcut: shortcut("diff.single_patch"), label: "All files / single file" },
1254
- ...(props.tree ? [{ shortcut: shortcut("diff.toggle_file_tree"), label: "Show / hide file tree" }] : []),
1255
- { shortcut: shortcut("diff.switch_source"), label: "Switch diff source" },
1256
- ...(props.fullscreen
1257
- ? [{ shortcut: shortcut("diff.toggle_fullscreen"), label: "Full screen / split view" }]
1258
- : []),
1259
- { shortcut: () => props.context.keymap.shortcuts("diff.close").join(" / "), label: "Close diff viewer" },
1260
- ],
1261
- },
1262
- ]
1263
-
1264
- return (
1265
- <DialogLayout
1266
- header={
1267
- <DialogHeader title="Diff shortcuts" closeLabel="esc close" onClose={() => props.context.ui.dialog.clear()} />
1268
- }
1269
- >
1270
- <scrollbox
1271
- id="diff-help-scroll"
1272
- focused
1273
- height={Math.max(
1274
- 1,
1275
- Math.min(
1276
- dimensions().height - 6,
1277
- groups.reduce((height, group) => height + group.rows.length + 2, -1),
1278
- ),
1279
- )}
1280
- horizontalScrollbarOptions={{ visible: false }}
1281
- verticalScrollbarOptions={{ visible: false }}
1282
- >
1283
- <box gap={1}>
1284
- <For each={groups}>
1285
- {(group) => (
1286
- <box flexShrink={0}>
1287
- <text fg={theme.text.base} attributes={TextAttributes.BOLD}>
1288
- {group.title}
1289
- </text>
1290
- <For each={group.rows}>
1291
- {(row) => (
1292
- <box flexDirection="row" gap={2}>
1293
- <text fg={theme.text.base} width={17} flexShrink={0}>
1294
- {row.shortcut() || "unbound"}
1295
- </text>
1296
- <text fg={theme.text.muted} flexGrow={1} minWidth={0}>
1297
- {row.label}
1298
- </text>
1299
- </box>
1300
- )}
1301
- </For>
1302
- </box>
1303
- )}
1304
- </For>
1305
- </box>
1306
- </scrollbox>
1307
- </DialogLayout>
1308
- )
1309
- }
1310
-
1311
- function Commands(props: { context: Plugin.Context }) {
1312
- const config = useConfig()
1313
- props.context.keymap.layer(() => ({
1314
- mode: "global",
1315
- commands: [
1316
- {
1317
- id: "diff.open",
1318
- title: "Open diff viewer",
1319
- slash: { name: "diff" },
1320
- group: "VCS",
1321
- palette: true,
1322
- run() {
1323
- const route = props.context.ui.router.current()
1324
- props.context.ui.dialog.clear()
1325
- const current = props.context.ui.panel.current()
1326
- if (route.type === "session" && current?.sessionID === route.sessionID && current.name === ROUTE) {
1327
- props.context.ui.panel.close()
1328
- return
1329
- }
1330
- // Outside a session there is no panel slot, so /diff falls back to the full-screen route.
1331
- if (
1332
- props.context.ui.panel.open(ROUTE, {
1333
- presentation: config.data.diffs?.fullscreen === true ? "fullscreen" : "panel",
1334
- })
1335
- )
1336
- return
1337
- const returnRoute: Route =
1338
- route.type === "home"
1339
- ? { type: "home" }
1340
- : route.type === "session"
1341
- ? { type: "session", sessionID: route.sessionID }
1342
- : {
1343
- type: "plugin",
1344
- id: route.id,
1345
- name: route.name,
1346
- ...(route.data ? { data: { ...route.data } } : {}),
1347
- }
1348
- props.context.ui.router.navigate({
1349
- type: "plugin",
1350
- name: ROUTE,
1351
- data: {
1352
- sessionID: route.type === "session" ? route.sessionID : undefined,
1353
- returnRoute,
1354
- },
1355
- })
1356
- },
1357
- },
1358
- ],
1359
- }))
1360
- return null
1361
- }
1362
-
1363
- export default Plugin.define({
1364
- id: "opencode.diffs",
1365
- setup(context) {
1366
- context.ui.slot({
1367
- append: "session.panel",
1368
- render: (panel) => (
1369
- <Show when={panel.name === ROUTE}>
1370
- <DiffViewer context={context} sessionID={panel.sessionID} panel={panel} onClose={panel.close} />
1371
- </Show>
1372
- ),
1373
- })
1374
- context.ui.router.register({
1375
- name: ROUTE,
1376
- render: ({ data }) => <DiffRoute context={context} data={data} />,
1377
- })
1378
- context.ui.slot({ append: "app", render: () => <Commands context={context} /> })
1379
- },
1380
- })
1
+ /** @jsxImportSource @opentui/solid */
2
+ import type { FileDiffInfo, LocationRef } from "@zyro-sec/client"
3
+ import type { Vcs } from "@zyro-sec/schema/vcs"
4
+ import { Plugin } from "@zyro-sec/plugin/tui"
5
+ import type { KeymapCommand, PanelInput, Route } from "@zyro-sec/plugin/tui/context"
6
+ import {
7
+ MouseButton,
8
+ TextAttributes,
9
+ type BoxRenderable,
10
+ type RGBA,
11
+ type MouseEvent,
12
+ type ScrollBoxRenderable,
13
+ } from "@opentui/core"
14
+ import { filetype } from "../../util/filetype"
15
+ import { useRenderer, useTerminalDimensions } from "@opentui/solid"
16
+ import { createEffect, createMemo, createResource, createSignal, For, Match, onCleanup, Show, Switch } from "solid-js"
17
+ import { DiffViewerFileTree } from "./diff-viewer-file-tree"
18
+ import { DiffFileMenu } from "./diff-viewer-file-menu"
19
+ import { DiffViewerImage, isDiffImageFile } from "./diff-viewer-image"
20
+ import { DIALOG_LIST_INSET, DialogHeader, DialogLayout } from "../../ui/dialog"
21
+ import { DialogSelect } from "../../ui/dialog-select"
22
+ import { EmptyBorder } from "../../ui/border"
23
+ import { SESSION_PANEL_SPLIT_MIN_WIDTH } from "../../ui/layout"
24
+ import { FilePath } from "../../ui/file-path"
25
+ import { getScrollAcceleration } from "../../util/scroll"
26
+ import { createDebouncedSignal } from "../../util/signal"
27
+ import { type DiffSource, useConfig } from "../../config"
28
+ import { locationKey } from "../../context/data"
29
+ import { useTheme, useThemes } from "../../context/theme"
30
+ import { PatchDiff, type PatchDiffRef } from "../../component/patch-diff"
31
+ import {
32
+ allExpandedFileTreeDirectories,
33
+ buildFileTree,
34
+ fileTreeFileSelection,
35
+ type FileTreeRow,
36
+ flattenFileTree,
37
+ movePatchFileIndex,
38
+ orderedPatchFileIndexes,
39
+ showDiffViewerFileTree,
40
+ singlePatchFileIndex,
41
+ toggleFileTreeDirectory,
42
+ } from "./diff-viewer-file-tree-utils"
43
+
44
+ const ROUTE = "diff"
45
+ const MIN_SPLIT_WIDTH = 100
46
+ const FILE_TREE_MIN_WIDTH = 30
47
+ const FILE_TREE_MAX_WIDTH = 40
48
+ const FULL_INSET = 2
49
+ // The full layout keeps its file tree and inset cards only while its patches stay as wide as the narrowest docked
50
+ // panel, an equal split at the host's split threshold. Narrower full screens use the compact panel layout.
51
+ const FULL_LAYOUT_MIN_WIDTH = FILE_TREE_MIN_WIDTH + FULL_INSET * 2 + Math.floor(SESSION_PANEL_SPLIT_MIN_WIDTH / 2)
52
+ const FILE_HEADER_HEIGHT = 2
53
+ const VCS_DIFF_CONTEXT_LINES = 12
54
+ type DiffMode = DiffSource
55
+ type DiffView = "split" | "unified"
56
+ type SelectedHunk = { readonly fileIndex: number; readonly hunkIndex: number; readonly scrollTop: number }
57
+ type FileMenuState = { readonly fileIndex: number; readonly x: number; readonly y: number }
58
+
59
+ export type DiffFile = {
60
+ readonly file: string
61
+ readonly patch?: string
62
+ readonly additions: number
63
+ readonly deletions: number
64
+ readonly status: "added" | "deleted" | "modified"
65
+ }
66
+
67
+ const normalizeDiffs = (diffs: readonly FileDiffInfo[]): DiffFile[] =>
68
+ diffs.map((item) => ({
69
+ file: item.file,
70
+ patch: item.patch,
71
+ additions: item.additions,
72
+ deletions: item.deletions,
73
+ status: item.status,
74
+ }))
75
+
76
+ function storedView(value: unknown): DiffView | undefined {
77
+ if (value === "split" || value === "unified") return value
78
+ }
79
+
80
+ const DIFF_SOURCES = {
81
+ branch: { label: "All", description: "Branch + local changes" },
82
+ committed: { label: "Committed", description: "Branch commits only" },
83
+ working: { label: "Uncommitted", description: "Local changes only" },
84
+ turn: { label: "Last turn", description: "Latest session turn" },
85
+ } satisfies Record<DiffMode, { label: string; description: string }>
86
+
87
+ const VCS_SOURCES = ["branch", "committed", "working"] as const
88
+
89
+ const needsBase = (mode: DiffMode) => mode === "branch" || mode === "committed"
90
+
91
+ function DiffViewer(props: {
92
+ context: Plugin.Context
93
+ sessionID?: string
94
+ initialMode?: DiffMode
95
+ panel?: PanelInput
96
+ onClose: () => void
97
+ }) {
98
+ const config = useConfig()
99
+ const [memory, updateMemory] = props.context.storage.memory<{
100
+ source?: DiffMode
101
+ bases: Record<string, string>
102
+ }>("review", { initial: { bases: {} } })
103
+ const sessionID = () => props.sessionID
104
+ const sources = (): readonly DiffMode[] => (sessionID() ? [...VCS_SOURCES, "turn"] : VCS_SOURCES)
105
+ const initialMode = props.initialMode ?? memory.source ?? config.data.diffs?.source ?? "branch"
106
+ const [mode, setMode] = createSignal(sources().includes(initialMode) ? initialMode : "branch")
107
+ const location = createMemo(
108
+ () => {
109
+ const id = sessionID()
110
+ return id
111
+ ? (props.context.data.session.get(id)?.location ?? props.context.data.location.default())
112
+ : props.context.data.location.default()
113
+ },
114
+ undefined,
115
+ { equals: (a, b) => a.directory === b.directory },
116
+ )
117
+ const baseKey = createMemo(() =>
118
+ JSON.stringify([locationKey(location()), props.context.data.location.vcs.info(location())?.branch.current]),
119
+ )
120
+ const selectedBase = () => memory.bases[baseKey()]
121
+ // Mode changes share the same lazy base lookup until this viewer is closed.
122
+ const bases = new Map<string, ReturnType<Plugin.Context["client"]["vcs"]["base"]>>()
123
+ const [reportedBases, setReportedBases] = createSignal<ReadonlyMap<string, Vcs.Base | null>>(new Map())
124
+ const loadBase = (location: LocationRef, key: string) => {
125
+ const cached = bases.get(key)
126
+ if (cached) return cached
127
+ const pending = props.context.client.vcs.base({ location }).then((result) => {
128
+ setReportedBases((known) => new Map(known).set(key, result.data))
129
+ return result
130
+ })
131
+ bases.set(key, pending)
132
+ return pending
133
+ }
134
+ const diffInput = createMemo(() => {
135
+ const current = mode()
136
+ const id = sessionID()
137
+ if (current === "turn" && id) return { mode: current, sessionID: id }
138
+ const vcs = current === "turn" ? "branch" : current
139
+ return {
140
+ mode: vcs,
141
+ location: location(),
142
+ key: baseKey(),
143
+ selected: needsBase(vcs) ? selectedBase() : undefined,
144
+ }
145
+ })
146
+ const [diff, { refetch }] = createResource(diffInput, async (input) => {
147
+ if (input.mode === "turn") {
148
+ return {
149
+ base: null,
150
+ files: normalizeDiffs(
151
+ await props.context.client.session.diff({ sessionID: input.sessionID, context: VCS_DIFF_CONTEXT_LINES }),
152
+ ),
153
+ }
154
+ }
155
+ const base = !needsBase(input.mode)
156
+ ? undefined
157
+ : input.selected
158
+ ? { name: input.selected, ref: input.selected }
159
+ : (await loadBase(input.location, input.key)).data
160
+ if (input !== diffInput() || (input.mode === "committed" && !base)) {
161
+ return { base: null, files: [] }
162
+ }
163
+ const result = await props.context.client.vcs.diff({
164
+ location: input.location,
165
+ mode: input.mode,
166
+ ...(base ? { base: base.ref } : {}),
167
+ context: VCS_DIFF_CONTEXT_LINES,
168
+ })
169
+ return { base, files: normalizeDiffs(result.data ?? []) }
170
+ })
171
+ // Each completed turn replaces the last one.
172
+ createEffect((previous) => {
173
+ if (mode() !== "turn") return undefined
174
+ const id = sessionID()
175
+ const status = id ? props.context.data.session.status(id) : undefined
176
+ if (previous === "running" && status === "idle") void refetch()
177
+ return status
178
+ })
179
+ const sourceBase = () => {
180
+ const ref = selectedBase()
181
+ return ref ? { name: ref, ref } : reportedBases().get(baseKey())
182
+ }
183
+ const result = () => (diff.error || diff.loading ? undefined : diff())
184
+ const sourceDetail = () => {
185
+ if (mode() === "turn") return diff.error ? "Diff unavailable" : undefined
186
+ if (mode() === "working") return "vs HEAD"
187
+ if (diff.error) return "Base or diff unavailable"
188
+ if (!result()) return "Resolving diff…"
189
+ const base = result()?.base
190
+ if (!base) return "Base not reported"
191
+ return `vs ${base.name}`
192
+ }
193
+ return (
194
+ <DiffViewerContent
195
+ context={props.context}
196
+ files={result()?.files ?? []}
197
+ loading={diff.loading}
198
+ error={diff.error}
199
+ mode={mode()}
200
+ sources={sources()}
201
+ sourceDetail={sourceDetail()}
202
+ sourceBase={sourceBase()}
203
+ unavailable={mode() === "committed" && !!result() && !result()?.base}
204
+ preferences={config.data.diffs}
205
+ panel={props.panel}
206
+ loadImage={(file, signal) => props.context.client.file.read({ path: file, location: location() }, { signal })}
207
+ onPreferencesChange={(value) => {
208
+ void config
209
+ .update((draft) => {
210
+ draft.diffs = { ...draft.diffs, ...value }
211
+ })
212
+ .catch(() => {})
213
+ }}
214
+ onClose={props.onClose}
215
+ onSwitchSource={(mode) => {
216
+ updateMemory((draft) => {
217
+ draft.source = mode
218
+ })
219
+ setMode(mode)
220
+ }}
221
+ onChooseBase={() => {
222
+ const target = { ...location() }
223
+ const key = baseKey()
224
+ if (!memory.bases[key]) void loadBase(target, key).catch(() => {})
225
+ props.context.ui.dialog.show(() => (
226
+ <DiffBaseDialog
227
+ context={props.context}
228
+ location={target}
229
+ current={memory.bases[key] ?? reportedBases().get(key)?.ref}
230
+ onSelect={(ref) =>
231
+ updateMemory((draft) => {
232
+ draft.bases[key] = ref
233
+ })
234
+ }
235
+ />
236
+ ))
237
+ }}
238
+ />
239
+ )
240
+ }
241
+
242
+ function DiffRoute(props: {
243
+ context: Plugin.Context
244
+ data?: { mode?: DiffMode; sessionID?: string; returnRoute?: Route }
245
+ }) {
246
+ const dimensions = useTerminalDimensions()
247
+ return (
248
+ <box position="absolute" zIndex={2500} left={0} top={0} width={dimensions().width} height={dimensions().height}>
249
+ <DiffViewer
250
+ context={props.context}
251
+ sessionID={props.data?.sessionID}
252
+ initialMode={props.data?.mode}
253
+ onClose={() => props.context.ui.router.navigate(props.data?.returnRoute ?? { type: "home" })}
254
+ />
255
+ </box>
256
+ )
257
+ }
258
+
259
+ function DiffBaseDialog(props: {
260
+ context: Plugin.Context
261
+ location: LocationRef
262
+ current?: string
263
+ onSelect: (ref: string) => void
264
+ }) {
265
+ const theme = props.context.theme.surface("dialog")
266
+ const [search, setSearch] = createDebouncedSignal("", 150)
267
+ const [branches] = createResource(search, (search) =>
268
+ props.context.client.vcs.branch.list({ location: props.location, search, limit: 100 }),
269
+ )
270
+ const Empty = () => (
271
+ <box paddingLeft={DIALOG_LIST_INSET} paddingRight={DIALOG_LIST_INSET}>
272
+ <text fg={branches.error ? theme.text.feedback.error.base : theme.text.muted}>
273
+ {branches.loading
274
+ ? "Loading branches…"
275
+ : branches.error
276
+ ? "Could not load branches. Reopen the picker to try again."
277
+ : "No branches found"}
278
+ </text>
279
+ </box>
280
+ )
281
+
282
+ return (
283
+ <DialogSelect
284
+ title="Base branch"
285
+ placeholder="Search local and remote branches"
286
+ skipFilter
287
+ current={props.current?.replace(/^refs\/(heads|remotes)\//, "")}
288
+ onFilter={setSearch}
289
+ emptyView={<Empty />}
290
+ noMatchView={<Empty />}
291
+ footer={<text fg={theme.text.muted}>Remembered until the TUI exits</text>}
292
+ options={(branches.loading || branches.error ? [] : (branches()?.data ?? [])).map((name) => ({
293
+ title: name,
294
+ value: name,
295
+ onSelect() {
296
+ props.onSelect(name)
297
+ props.context.ui.dialog.clear()
298
+ },
299
+ }))}
300
+ />
301
+ )
302
+ }
303
+
304
+ type DiffPreferences = { tree?: boolean; single?: boolean; view?: "auto" | DiffView; fullscreen?: boolean }
305
+
306
+ export function DiffViewerContent(props: {
307
+ context: Plugin.Context
308
+ files: readonly DiffFile[]
309
+ loading?: boolean
310
+ error?: unknown
311
+ mode: DiffMode
312
+ sources: readonly DiffMode[]
313
+ sourceDetail?: string
314
+ sourceBase?: Pick<Vcs.Base, "name" | "ref"> | null
315
+ unavailable?: boolean
316
+ loadImage?: (file: string, signal: AbortSignal) => Promise<Uint8Array>
317
+ preferences?: DiffPreferences
318
+ panel?: PanelInput
319
+ onPreferencesChange?: (value: DiffPreferences) => void
320
+ onClose: () => void
321
+ onSwitchSource: (mode: DiffMode) => void
322
+ onChooseBase?: () => void
323
+ }) {
324
+ const renderer = useRenderer()
325
+ const dimensions = useTerminalDimensions()
326
+ const config = useConfig()
327
+ const dialog = props.context.ui.dialog
328
+ const theme = useTheme()
329
+ const currentSyntax = useThemes().currentSyntax
330
+ const files = () => props.files
331
+ const docked = () => props.panel?.presentation === "panel"
332
+ const width = () => props.panel?.width ?? dimensions().width
333
+ // Docked panels and narrow full screens share the compact layout: no file tree, flush cards, and a footer.
334
+ const compact = () => docked() || width() < FULL_LAYOUT_MIN_WIDTH
335
+ // Full screen has no pane beside it to focus, and is always the active input scope.
336
+ const focused = () => !docked() || props.panel?.focused === true
337
+ // The side panel sits on the slot's raised surface; full screen keeps the base background.
338
+ const surface = () => (docked() ? theme.background.raised.base : theme.background.base)
339
+ // Cards are inset from the pane edges; the gaps between them run edge to edge.
340
+ const inset = () => (compact() ? 0 : FULL_INSET)
341
+ const mode = () => props.mode
342
+ const [fileTreeEnabled, setFileTreeEnabled] = createSignal(props.preferences?.tree ?? true)
343
+ const showFileTree = createMemo(() => !compact() && showDiffViewerFileTree(fileTreeEnabled(), files().length))
344
+ const [singlePatch, setSinglePatch] = createSignal(props.preferences?.single ?? false)
345
+ const fileTreeWidth = createMemo(() =>
346
+ Math.max(FILE_TREE_MIN_WIDTH, Math.min(FILE_TREE_MAX_WIDTH, Math.floor(width() / 4))),
347
+ )
348
+ const patchPaneWidth = createMemo(() => width() - (showFileTree() ? fileTreeWidth() : 0) - inset() * 2)
349
+ const splitAvailable = createMemo(() => patchPaneWidth() >= MIN_SPLIT_WIDTH)
350
+ const [viewOverride, setViewOverride] = createSignal<DiffView | undefined>(storedView(props.preferences?.view))
351
+ const view = createMemo(() =>
352
+ splitAvailable() ? (viewOverride() ?? storedView(props.preferences?.view) ?? "split") : "unified",
353
+ )
354
+ const fileTree = createMemo(() => buildFileTree(files()))
355
+ const [expandedFileNodes, setExpandedFileNodes] = createSignal<ReadonlySet<number>>(new Set())
356
+ const [selectedFileIndex, setSelectedFileIndex] = createSignal<number | undefined>()
357
+ const [reviewedFileNames, setReviewedFileNames] = createSignal<ReadonlySet<string>>(new Set())
358
+ const [exhaustedFileIndex, setExhaustedFileIndex] = createSignal<number | undefined>()
359
+ const [fileMenu, setFileMenu] = createSignal<FileMenuState>()
360
+ const patchScrollAcceleration = createMemo(() => getScrollAcceleration(config.data))
361
+ const patchFileIndexes = createMemo(() => orderedPatchFileIndexes(flattenFileTree(fileTree())))
362
+ const helpShortcut = () => props.context.keymap.shortcuts("diff.help")[0]
363
+ let scroll: ScrollBoxRenderable | undefined
364
+ const patchNodeByFileIndex = new Map<number, BoxRenderable>()
365
+ const patchDiffByFileIndex = new Map<number, PatchDiffRef>()
366
+ const [selectedHunk, setSelectedHunk] = createSignal<SelectedHunk | undefined>()
367
+ const [pendingPatchScrollFileIndex, setPendingPatchScrollFileIndex] = createSignal<number | undefined>()
368
+
369
+ createEffect(() => {
370
+ setExpandedFileNodes(allExpandedFileTreeDirectories(fileTree()))
371
+ setSelectedFileIndex(undefined)
372
+ setSelectedHunk(undefined)
373
+ setReviewedFileNames(new Set<string>())
374
+ setExhaustedFileIndex(undefined)
375
+ setFileMenu(undefined)
376
+ })
377
+
378
+ const clearPatchSelection = () => {
379
+ setPendingPatchScrollFileIndex(undefined)
380
+ setSelectedHunk(undefined)
381
+ if (!singlePatch()) setSelectedFileIndex(undefined)
382
+ }
383
+
384
+ const scrollPage = (direction: -1 | 1, divisor: 1 | 2) => {
385
+ clearPatchSelection()
386
+ if (scroll) scroll.scrollBy(direction * Math.max(1, Math.floor(scroll.viewport.height / divisor)))
387
+ }
388
+
389
+ const scrollPatchNodeToTop = (patchNode: BoxRenderable, offset?: number) => {
390
+ if (!scroll || patchNode.isDestroyed) return
391
+ const contentY = patchNode.y - scroll.content.y
392
+ // The fixed pane edge replaces the leading separator when jumping to a later file.
393
+ scroll.scrollTo(contentY + (offset ?? (contentY > 0 ? 1 : 0)))
394
+ }
395
+
396
+ const revealFileTreeFile = (fileIndex: number) => {
397
+ const selection = fileTreeFileSelection(fileTree(), fileIndex)
398
+ if (!selection) return
399
+ setExpandedFileNodes((expanded) => {
400
+ if ([...selection.expandedNodes].every((node) => expanded.has(node))) return expanded
401
+ const next = new Set(expanded)
402
+ selection.expandedNodes.forEach((node) => next.add(node))
403
+ return next
404
+ })
405
+ }
406
+
407
+ const selectPatchFile = (fileIndex: number) => {
408
+ setPendingPatchScrollFileIndex(undefined)
409
+ setExhaustedFileIndex(undefined)
410
+ revealFileTreeFile(fileIndex)
411
+ setSelectedFileIndex(fileIndex)
412
+ }
413
+
414
+ const scrollToFileIndex = (fileIndex: number | undefined) => {
415
+ if (fileIndex === undefined) return
416
+ selectPatchFile(fileIndex)
417
+ const patchNode = patchNodeByFileIndex.get(fileIndex)
418
+ if (patchNode) scrollPatchNodeToTop(patchNode)
419
+ }
420
+
421
+ const jumpToFileIndex = (fileIndex: number | undefined) => {
422
+ if (fileIndex === undefined) return
423
+ setSelectedHunk(undefined)
424
+ scrollToFileIndex(fileIndex)
425
+ if (singlePatch()) scrollSinglePatchToTop()
426
+ }
427
+
428
+ const currentPatchFileIndex = () => {
429
+ if (!scroll) return undefined
430
+ const viewportContentY = scroll.scrollTop + 1
431
+ const entries = patchFileIndexes()
432
+ .map((fileIndex) => ({
433
+ fileIndex,
434
+ node: patchNodeByFileIndex.get(fileIndex),
435
+ }))
436
+ .filter((entry): entry is { fileIndex: number; node: BoxRenderable } => Boolean(entry.node))
437
+ .map((entry) => ({
438
+ ...entry,
439
+ contentY: scroll!.scrollTop + entry.node.y - scroll!.viewport.y,
440
+ }))
441
+ .sort((left, right) => left.contentY - right.contentY)
442
+ return entries.findLast((entry) => entry.contentY <= viewportContentY)?.fileIndex ?? entries[0]?.fileIndex
443
+ }
444
+
445
+ const jumpRelativePatchFile = (offset: number) => {
446
+ setSelectedHunk(undefined)
447
+ const next = movePatchFileIndex(patchFileIndexes(), selectedFileIndex() ?? currentPatchFileIndex(), offset)
448
+ if (singlePatch()) {
449
+ if (next === undefined) return
450
+ selectPatchFile(next)
451
+ scrollSinglePatchToTop()
452
+ return
453
+ }
454
+ scrollToFileIndex(next)
455
+ }
456
+
457
+ const jumpRelativeHunk = (offset: -1 | 1) => {
458
+ const patchScroll = scroll
459
+ if (!patchScroll) return
460
+ const hunks = visiblePatchFiles()
461
+ .flatMap((entry) => {
462
+ return (
463
+ patchDiffByFileIndex
464
+ .get(entry.fileIndex)
465
+ ?.hunks()
466
+ .map((node, hunkIndex) => ({
467
+ fileIndex: entry.fileIndex,
468
+ hunkIndex,
469
+ contentY: patchScroll.scrollTop + node.y - patchScroll.viewport.y - (hunkIndex > 0 ? 1 : 0),
470
+ })) ?? []
471
+ )
472
+ })
473
+ .sort((left, right) => left.contentY - right.contentY)
474
+ const selected = selectedHunk()
475
+ const selectedIndex =
476
+ selected?.scrollTop === patchScroll.scrollTop
477
+ ? hunks.findIndex((hunk) => hunk.fileIndex === selected.fileIndex && hunk.hunkIndex === selected.hunkIndex)
478
+ : -1
479
+ const contentTop = patchScroll.scrollTop + FILE_HEADER_HEIGHT
480
+ const next =
481
+ selectedIndex !== -1
482
+ ? hunks[selectedIndex + offset]
483
+ : offset === 1
484
+ ? hunks.find((hunk) => hunk.contentY > contentTop)
485
+ : hunks.findLast((hunk) => hunk.contentY < contentTop)
486
+ if (!next) return
487
+ selectPatchFile(next.fileIndex)
488
+ patchScroll.scrollTo(Math.max(0, next.contentY - FILE_HEADER_HEIGHT))
489
+ setSelectedHunk({ fileIndex: next.fileIndex, hunkIndex: next.hunkIndex, scrollTop: patchScroll.scrollTop })
490
+ }
491
+
492
+ const firstPatchFileIndex = () => patchFileIndexes()[0]
493
+ const visiblePatchFiles = createMemo(() => {
494
+ if (!singlePatch()) {
495
+ return patchFileIndexes().flatMap((fileIndex) => {
496
+ const file = files()[fileIndex]
497
+ return file ? [{ file, fileIndex }] : []
498
+ })
499
+ }
500
+ const fileIndex = singlePatchFileIndex(selectedFileIndex(), currentPatchFileIndex(), firstPatchFileIndex())
501
+ const file = fileIndex === undefined ? undefined : files()[fileIndex]
502
+ return file && fileIndex !== undefined ? [{ file, fileIndex }] : []
503
+ })
504
+
505
+ const ensureHighlightedPatchFile = () => {
506
+ const fileIndex = currentPatchFileIndex() ?? selectedFileIndex() ?? firstPatchFileIndex()
507
+ if (fileIndex === undefined) return
508
+ selectPatchFile(fileIndex)
509
+ }
510
+
511
+ const scrollToPatchFileIndexAfterRender = (fileIndex: number, offset?: number) => {
512
+ setPendingPatchScrollFileIndex(fileIndex)
513
+ renderer.requestAnimationFrame(() => {
514
+ if (pendingPatchScrollFileIndex() !== fileIndex) return
515
+ const patchNode = patchNodeByFileIndex.get(fileIndex)
516
+ if (patchNode) scrollPatchNodeToTop(patchNode, offset)
517
+ renderer.requestAnimationFrame(() => {
518
+ if (pendingPatchScrollFileIndex() !== fileIndex) return
519
+ const patchNode = patchNodeByFileIndex.get(fileIndex)
520
+ if (patchNode) scrollPatchNodeToTop(patchNode, offset)
521
+ setPendingPatchScrollFileIndex(undefined)
522
+ })
523
+ })
524
+ }
525
+
526
+ const scrollSinglePatchToTop = () => {
527
+ renderer.requestAnimationFrame(() => {
528
+ scroll?.scrollTo(0)
529
+ renderer.requestAnimationFrame(() => scroll?.scrollTo(0))
530
+ })
531
+ }
532
+
533
+ const registerPatchNode = (fileIndex: number, element: BoxRenderable) => {
534
+ patchNodeByFileIndex.set(fileIndex, element)
535
+ if (pendingPatchScrollFileIndex() !== fileIndex) return
536
+ scrollToPatchFileIndexAfterRender(fileIndex)
537
+ }
538
+
539
+ const clickFileTreeRow = (row: FileTreeRow) => {
540
+ if (row.fileIndex !== undefined) {
541
+ jumpToFileIndex(row.fileIndex)
542
+ return
543
+ }
544
+ setExpandedFileNodes((expanded) => toggleFileTreeDirectory(fileTree(), expanded, row.id))
545
+ }
546
+
547
+ const toggleFileReviewed = (fileIndex: number | undefined) => {
548
+ if (fileIndex === undefined) return
549
+ const file = files()[fileIndex]?.file
550
+ if (!file) return
551
+ const current = selectedFileIndex() ?? currentPatchFileIndex()
552
+ const anchor = current === undefined ? undefined : patchNodeByFileIndex.get(current)
553
+ const offset = anchor && scroll ? scroll.viewport.y - anchor.y : undefined
554
+ const reviewed = reviewedFileNames().has(file)
555
+ setReviewedFileNames((reviewed) => {
556
+ const next = new Set(reviewed)
557
+ if (next.has(file)) next.delete(file)
558
+ else next.add(file)
559
+ return next
560
+ })
561
+ // Completing another file from its menu must not navigate away from the current file.
562
+ if (fileIndex !== current) {
563
+ if (current !== undefined && offset !== undefined && !singlePatch())
564
+ scrollToPatchFileIndexAfterRender(current, offset)
565
+ return
566
+ }
567
+ const nextFileIndex =
568
+ singlePatch() && !reviewed ? (movePatchFileIndex(patchFileIndexes(), fileIndex, 1) ?? fileIndex) : fileIndex
569
+ selectPatchFile(nextFileIndex)
570
+ if (singlePatch() && !reviewed && nextFileIndex === fileIndex) setExhaustedFileIndex(fileIndex)
571
+ setSelectedHunk(undefined)
572
+ scrollToPatchFileIndexAfterRender(nextFileIndex)
573
+ }
574
+
575
+ const openFileMenu = (fileIndex: number, event: MouseEvent) => {
576
+ if (event.button !== MouseButton.RIGHT) return
577
+ event.preventDefault()
578
+ event.stopPropagation()
579
+ props.panel?.focus()
580
+ setFileMenu({ fileIndex, x: event.x, y: event.y })
581
+ }
582
+
583
+ const close = () => {
584
+ dialog.clear()
585
+ props.onClose()
586
+ }
587
+
588
+ const commands: KeymapCommand[] = [
589
+ {
590
+ id: "diff.close",
591
+ title: "Close diff viewer",
592
+ group: "VCS",
593
+ run: close,
594
+ },
595
+ {
596
+ id: "diff.down",
597
+ title: "Move diff viewer down",
598
+ group: "VCS",
599
+ run() {
600
+ clearPatchSelection()
601
+ scroll?.scrollBy(1)
602
+ },
603
+ },
604
+ {
605
+ id: "diff.up",
606
+ title: "Move diff viewer up",
607
+ group: "VCS",
608
+ run() {
609
+ clearPatchSelection()
610
+ scroll?.scrollBy(-1)
611
+ },
612
+ },
613
+ {
614
+ id: "diff.page.down",
615
+ title: "Page diff viewer down",
616
+ group: "VCS",
617
+ run: () => scrollPage(1, 1),
618
+ },
619
+ {
620
+ id: "diff.page.up",
621
+ title: "Page diff viewer up",
622
+ group: "VCS",
623
+ run: () => scrollPage(-1, 1),
624
+ },
625
+ {
626
+ id: "diff.half_page.down",
627
+ title: "Scroll down half a page",
628
+ group: "VCS",
629
+ run: () => scrollPage(1, 2),
630
+ },
631
+ {
632
+ id: "diff.half_page.up",
633
+ title: "Scroll up half a page",
634
+ group: "VCS",
635
+ run: () => scrollPage(-1, 2),
636
+ },
637
+ {
638
+ id: "diff.first",
639
+ title: "Go to the start of the diff",
640
+ group: "VCS",
641
+ run() {
642
+ clearPatchSelection()
643
+ scroll?.scrollTo(0)
644
+ },
645
+ },
646
+ {
647
+ id: "diff.last",
648
+ title: "Go to the end of the diff",
649
+ group: "VCS",
650
+ run() {
651
+ clearPatchSelection()
652
+ if (scroll) scroll.scrollTo(scroll.scrollHeight)
653
+ },
654
+ },
655
+ {
656
+ id: "diff.next_hunk",
657
+ title: "Jump to next diff hunk",
658
+ group: "VCS",
659
+ run() {
660
+ jumpRelativeHunk(1)
661
+ },
662
+ },
663
+ {
664
+ id: "diff.previous_hunk",
665
+ title: "Jump to previous diff hunk",
666
+ group: "VCS",
667
+ run() {
668
+ jumpRelativeHunk(-1)
669
+ },
670
+ },
671
+ {
672
+ id: "diff.next_file",
673
+ title: "Jump to next diff file",
674
+ group: "VCS",
675
+ run() {
676
+ jumpRelativePatchFile(1)
677
+ },
678
+ },
679
+ {
680
+ id: "diff.previous_file",
681
+ title: "Jump to previous diff file",
682
+ group: "VCS",
683
+ run() {
684
+ jumpRelativePatchFile(-1)
685
+ },
686
+ },
687
+ {
688
+ id: "diff.mark_reviewed",
689
+ title: "Toggle selected diff file reviewed",
690
+ group: "VCS",
691
+ run() {
692
+ const fileIndex = selectedFileIndex() ?? currentPatchFileIndex()
693
+ if (fileIndex !== undefined && fileIndex === exhaustedFileIndex()) return
694
+ toggleFileReviewed(fileIndex)
695
+ },
696
+ },
697
+ {
698
+ id: "diff.toggle_file_tree",
699
+ title: "Toggle diff viewer file tree",
700
+ group: "VCS",
701
+ enabled: () => !compact(),
702
+ run() {
703
+ if (compact()) return
704
+ const next = !fileTreeEnabled()
705
+ setFileTreeEnabled(next)
706
+ props.onPreferencesChange?.({ tree: next })
707
+ },
708
+ },
709
+ {
710
+ id: "diff.single_patch",
711
+ title: "Toggle single patch view",
712
+ group: "VCS",
713
+ run() {
714
+ setSelectedHunk(undefined)
715
+ if (!singlePatch()) {
716
+ ensureHighlightedPatchFile()
717
+ setSinglePatch(true)
718
+ props.onPreferencesChange?.({ single: true })
719
+ scrollSinglePatchToTop()
720
+ return
721
+ }
722
+ const fileIndex =
723
+ visiblePatchFiles()[0]?.fileIndex ??
724
+ singlePatchFileIndex(selectedFileIndex(), currentPatchFileIndex(), firstPatchFileIndex())
725
+ if (fileIndex !== undefined) selectPatchFile(fileIndex)
726
+ setSinglePatch(false)
727
+ props.onPreferencesChange?.({ single: false })
728
+ if (fileIndex !== undefined) scrollToPatchFileIndexAfterRender(fileIndex)
729
+ },
730
+ },
731
+ {
732
+ id: "diff.switch_source",
733
+ title: "Switch diff viewer source",
734
+ group: "VCS",
735
+ run() {
736
+ openSwitchDiffDialog()
737
+ },
738
+ },
739
+ {
740
+ id: "diff.toggle_view",
741
+ title: "Toggle diff viewer split or unified view",
742
+ group: "VCS",
743
+ run() {
744
+ if (!splitAvailable()) return
745
+ setSelectedHunk(undefined)
746
+ const next = view() === "split" ? "unified" : "split"
747
+ setViewOverride(next)
748
+ props.onPreferencesChange?.({ view: next })
749
+ },
750
+ },
751
+ {
752
+ id: "diff.toggle_fullscreen",
753
+ title: "Toggle diff viewer full screen",
754
+ group: "VCS",
755
+ enabled: () => props.panel !== undefined,
756
+ run: () => {
757
+ const panel = props.panel
758
+ if (!panel) return
759
+ const before = panel.presentation
760
+ panel.toggleFullscreen()
761
+ // A narrow terminal forces full screen and ignores the toggle; only a real toggle is remembered.
762
+ if (panel.presentation === before) return
763
+ props.onPreferencesChange?.({ fullscreen: panel.presentation === "fullscreen" })
764
+ },
765
+ },
766
+ {
767
+ id: "diff.help",
768
+ title: "Show more diff viewer shortcuts",
769
+ group: "VCS",
770
+ run() {
771
+ openHelpDialog()
772
+ },
773
+ },
774
+ // Specific diff bindings take precedence over app.exit's Ctrl+D binding.
775
+ {
776
+ id: "app.exit",
777
+ title: "Close diff viewer",
778
+ group: "VCS",
779
+ run: close,
780
+ },
781
+ ]
782
+
783
+ const openSwitchDiffDialog = () => {
784
+ dialog.show(() => (
785
+ <DialogSelect<DiffMode | "base">
786
+ title="Diff source"
787
+ skipFilter={true}
788
+ renderFilter={false}
789
+ current={mode()}
790
+ options={[
791
+ ...props.sources.map((source) => ({
792
+ value: source,
793
+ title: DIFF_SOURCES[source].label,
794
+ titleView: DIFF_SOURCES[source].label.padEnd(11),
795
+ description: DIFF_SOURCES[source].description,
796
+ onSelect() {
797
+ dialog.clear()
798
+ props.onSwitchSource(source)
799
+ },
800
+ })),
801
+ ...(props.onChooseBase
802
+ ? [
803
+ {
804
+ title: "Base",
805
+ titleView: "Base".padEnd(11),
806
+ value: "base" as const,
807
+ description: props.sourceBase?.name ?? "Choose…",
808
+ onSelect: props.onChooseBase,
809
+ },
810
+ ]
811
+ : []),
812
+ ]}
813
+ />
814
+ ))
815
+ }
816
+
817
+ const openHelpDialog = () => {
818
+ dialog.show(() => (
819
+ <DiffViewerHelpDialog
820
+ context={props.context}
821
+ single={singlePatch()}
822
+ fullscreen={props.panel !== undefined}
823
+ tree={!compact()}
824
+ />
825
+ ))
826
+ dialog.set({ size: "medium", centered: true })
827
+ }
828
+
829
+ const HelpShortcut = (props: { compact?: boolean; label?: string; muted?: boolean }) => (
830
+ <Show when={helpShortcut()}>
831
+ {(shortcut) => (
832
+ <text
833
+ id="diff-help-shortcut"
834
+ fg={props.muted ? theme.text.action.primary.disabled : theme.text.base}
835
+ attributes={props.muted ? TextAttributes.DIM : 0}
836
+ selectable={false}
837
+ flexShrink={0}
838
+ wrapMode="none"
839
+ onMouseUp={(event) => {
840
+ if (event.button !== MouseButton.LEFT) return
841
+ event.stopPropagation()
842
+ openHelpDialog()
843
+ }}
844
+ >
845
+ {props.compact ? "?" : shortcut()}
846
+ <Show when={!props.compact}>
847
+ <span style={props.muted ? {} : { fg: theme.text.muted }}> {props.label ?? "help"}</span>
848
+ </Show>
849
+ </text>
850
+ )}
851
+ </Show>
852
+ )
853
+
854
+ props.context.keymap.layer(() => ({
855
+ commands,
856
+ }))
857
+
858
+ return (
859
+ <box width="100%" height="100%" backgroundColor={surface()}>
860
+ <Show when={!showFileTree()}>
861
+ <box
862
+ id="diff-source-header"
863
+ paddingLeft={2}
864
+ // Compact, the header lines up with the card text below it; the card edge row supplies the gap underneath.
865
+ paddingRight={compact() ? 1 : 2}
866
+ // Only the docked panel leaves a row above the header; full screen starts at the top edge.
867
+ paddingTop={docked() ? 1 : 0}
868
+ height={docked() ? 2 : 1}
869
+ flexShrink={0}
870
+ flexDirection="row"
871
+ gap={1}
872
+ >
873
+ <box
874
+ id="diff-source-switch"
875
+ flexDirection="row"
876
+ flexGrow={1}
877
+ minWidth={0}
878
+ onMouseUp={(event) => {
879
+ if (event.button !== MouseButton.LEFT) return
880
+ event.stopPropagation()
881
+ openSwitchDiffDialog()
882
+ }}
883
+ >
884
+ <text
885
+ fg={theme.text.action.secondary.base}
886
+ attributes={TextAttributes.BOLD}
887
+ selectable={false}
888
+ flexShrink={0}
889
+ wrapMode="none"
890
+ >
891
+ {DIFF_SOURCES[mode()].label}
892
+ </text>
893
+ <Show when={props.sourceDetail}>
894
+ <text fg={theme.text.muted} selectable={false} flexGrow={1} minWidth={0} wrapMode="none" truncate>
895
+ {` · ${props.sourceDetail}`}
896
+ </text>
897
+ </Show>
898
+ </box>
899
+ <text id="diff-review-count" fg={theme.text.muted} flexShrink={0} wrapMode="none">
900
+ {files().filter((file) => reviewedFileNames().has(file.file)).length}/{files().length}
901
+ </text>
902
+ </box>
903
+ </Show>
904
+ <box flexGrow={1} minHeight={0}>
905
+ <Switch>
906
+ <Match when={props.loading}>
907
+ <box flexGrow={1} padding={2} paddingTop={compact() ? 1 : 2}>
908
+ <text fg={theme.text.muted}>Loading diff…</text>
909
+ </box>
910
+ </Match>
911
+ <Match when={!props.loading && props.error}>
912
+ <box flexGrow={1} padding={2} paddingTop={compact() ? 1 : 2}>
913
+ <text fg={theme.text.feedback.error.base}>
914
+ {!props.sourceBase && needsBase(mode())
915
+ ? "Could not load diff. Choose a base branch from Diff source, or select Uncommitted."
916
+ : "Could not load diff. Reopen the diff viewer to try again."}
917
+ </text>
918
+ </box>
919
+ </Match>
920
+ <Match when={!props.loading && props.unavailable}>
921
+ <box flexGrow={1} padding={2} paddingTop={compact() ? 1 : 2}>
922
+ <text fg={theme.text.muted}>
923
+ Committed comparison unavailable without base metadata. Choose a base branch from Diff source.
924
+ </text>
925
+ </box>
926
+ </Match>
927
+ <Match when={!props.loading && files().length === 0}>
928
+ <box flexGrow={1} padding={2} paddingTop={compact() ? 1 : 2}>
929
+ <text fg={theme.text.muted}>No changes to show</text>
930
+ </box>
931
+ </Match>
932
+ <Match when={!props.loading}>
933
+ <box flexDirection="row" flexGrow={1} minHeight={0}>
934
+ <Show when={showFileTree()}>
935
+ <DiffViewerFileTree
936
+ files={files()}
937
+ loading={props.loading ?? false}
938
+ error={props.error}
939
+ width={fileTreeWidth()}
940
+ selectedFileIndex={
941
+ selectedFileIndex() ?? (singlePatch() ? visiblePatchFiles()[0]?.fileIndex : undefined)
942
+ }
943
+ reviewedFileNames={reviewedFileNames()}
944
+ expandedNodes={expandedFileNodes()}
945
+ onRowClick={clickFileTreeRow}
946
+ onFileContextMenu={openFileMenu}
947
+ source={DIFF_SOURCES[mode()].label}
948
+ sourceDetail={props.sourceDetail}
949
+ onSwitchSource={openSwitchDiffDialog}
950
+ footer={<HelpShortcut />}
951
+ />
952
+ </Show>
953
+
954
+ <box flexGrow={1} minWidth={0} minHeight={0}>
955
+ <box
956
+ id="diff-patch-top-edge"
957
+ marginLeft={inset()}
958
+ marginRight={inset()}
959
+ ref={(edge: BoxRenderable) => {
960
+ // The fixed edge belongs to the visible card, not the tree selection.
961
+ edge.onLifecyclePass = () => {
962
+ if (!scroll) return
963
+ const entry = visiblePatchFiles().findLast(
964
+ (entry) => (patchNodeByFileIndex.get(entry.fileIndex)?.y ?? Infinity) <= scroll!.viewport.y,
965
+ )
966
+ edge.backgroundColor =
967
+ entry && reviewedFileNames().has(entry.file.file)
968
+ ? theme.background.raised.high
969
+ : theme.diff.background.context
970
+ }
971
+ renderer.registerLifecyclePass(edge)
972
+ onCleanup(() => renderer.unregisterLifecyclePass(edge))
973
+ }}
974
+ height={1}
975
+ flexShrink={0}
976
+ backgroundColor={theme.diff.background.context}
977
+ />
978
+ <scrollbox
979
+ id="diff-patches"
980
+ ref={(element: ScrollBoxRenderable) => (scroll = element)}
981
+ flexGrow={1}
982
+ minHeight={0}
983
+ scrollAcceleration={patchScrollAcceleration()}
984
+ onMouseScroll={clearPatchSelection}
985
+ verticalScrollbarOptions={{ visible: false }}
986
+ horizontalScrollbarOptions={{ visible: false }}
987
+ >
988
+ <For each={visiblePatchFiles()}>
989
+ {(entry, index) => {
990
+ const reviewed = () => reviewedFileNames().has(entry.file.file)
991
+ const background = () =>
992
+ reviewed() ? theme.background.raised.high : theme.diff.background.context
993
+ const image = () => isDiffImageFile(entry.file.file)
994
+ const countsWidth = () =>
995
+ (image() ? 6 : String(entry.file.additions).length + String(entry.file.deletions).length + 5) +
996
+ (reviewed() ? 2 : 0)
997
+ return (
998
+ <box ref={(element: BoxRenderable) => registerPatchNode(entry.fileIndex, element)}>
999
+ <Show when={index() > 0}>
1000
+ <CardGap glyph="▄" card={background()} surface={surface()} inset={inset()} />
1001
+ </Show>
1002
+ <box backgroundColor={background()} marginLeft={inset()} marginRight={inset()}>
1003
+ <box
1004
+ id={`diff-file-header-${entry.fileIndex}`}
1005
+ onMouseDown={(event) => openFileMenu(entry.fileIndex, event)}
1006
+ ref={(header: BoxRenderable) => {
1007
+ // Move the original title without changing flow, bounded by its own card.
1008
+ header.onLifecyclePass = () => {
1009
+ if (!scroll || !header.parent) return
1010
+ header.translateY = Math.max(
1011
+ 0,
1012
+ Math.min(
1013
+ scroll.scrollTop - (header.parent.y - scroll.content.y),
1014
+ header.parent.height - header.height,
1015
+ ),
1016
+ )
1017
+ }
1018
+ renderer.registerLifecyclePass(header)
1019
+ onCleanup(() => renderer.unregisterLifecyclePass(header))
1020
+ }}
1021
+ flexDirection="row"
1022
+ gap={1}
1023
+ flexShrink={0}
1024
+ height={FILE_HEADER_HEIGHT}
1025
+ zIndex={1}
1026
+ backgroundColor={background()}
1027
+ paddingLeft={compact() ? 2 : 1}
1028
+ paddingRight={1}
1029
+ paddingBottom={1}
1030
+ >
1031
+ <box flexGrow={1} minWidth={0}>
1032
+ <FilePath
1033
+ value={entry.file.file}
1034
+ maxWidth={Math.max(1, patchPaneWidth() - countsWidth() - 2)}
1035
+ fg={theme.text.muted}
1036
+ basenameFg={reviewed() ? theme.text.muted : theme.text.base}
1037
+ />
1038
+ </box>
1039
+ <Show when={reviewed()}>
1040
+ <text fg={theme.text.muted} flexShrink={0}>
1041
+ ✓
1042
+ </text>
1043
+ </Show>
1044
+ <Show when={!image()} fallback={<text fg={theme.text.muted}>Image</text>}>
1045
+ <text flexShrink={0} fg={reviewed() ? theme.text.muted : theme.diff.text.added}>
1046
+ +{entry.file.additions}
1047
+ </text>
1048
+ <text flexShrink={0} fg={reviewed() ? theme.text.muted : theme.diff.text.removed}>
1049
+ -{entry.file.deletions}
1050
+ </text>
1051
+ </Show>
1052
+ <Show when={reviewed()}>
1053
+ <box position="absolute" left={-inset()} right={-inset()} bottom={0} height={1}>
1054
+ <CardGap glyph="▀" card={background()} surface={surface()} inset={inset()} />
1055
+ </box>
1056
+ </Show>
1057
+ </box>
1058
+ <Show when={!reviewed()}>
1059
+ <Switch
1060
+ fallback={
1061
+ <box
1062
+ width="100%"
1063
+ flexShrink={0}
1064
+ paddingLeft={compact() ? 2 : 1}
1065
+ paddingRight={1}
1066
+ paddingBottom={1}
1067
+ >
1068
+ <text fg={theme.text.muted}>
1069
+ {mode() === "committed" && image()
1070
+ ? "Committed image preview unavailable. The working-tree image is not shown."
1071
+ : entry.file.status === "deleted" && image()
1072
+ ? "Deleted image. The previous revision is not available for preview."
1073
+ : "No patch available for this file."}
1074
+ </text>
1075
+ </box>
1076
+ }
1077
+ >
1078
+ <Match
1079
+ when={
1080
+ mode() !== "committed" &&
1081
+ entry.file.status !== "deleted" &&
1082
+ image() &&
1083
+ props.loadImage
1084
+ }
1085
+ >
1086
+ {(load) => <DiffViewerImage file={entry.file.file} load={load()} />}
1087
+ </Match>
1088
+ <Match when={!(mode() === "committed" && image()) && entry.file.patch}>
1089
+ {(patch) => (
1090
+ <PatchDiff
1091
+ ref={(component) => {
1092
+ patchDiffByFileIndex.set(entry.fileIndex, component)
1093
+ onCleanup(() => patchDiffByFileIndex.delete(entry.fileIndex))
1094
+ }}
1095
+ diff={patch()}
1096
+ scroll={() => scroll}
1097
+ hunkFg={theme.diff.text.hunkHeader}
1098
+ view={entry.file.status === "modified" ? view() : "unified"}
1099
+ filetype={filetype(entry.file.file)}
1100
+ syntaxStyle={currentSyntax()}
1101
+ showLineNumbers={true}
1102
+ gutterPadding={compact() ? 1 : 0}
1103
+ width="100%"
1104
+ wrapMode="char"
1105
+ fg={theme.text.base}
1106
+ addedBg={theme.diff.background.added}
1107
+ removedBg={theme.diff.background.removed}
1108
+ contextBg={theme.diff.background.context}
1109
+ addedSignColor={theme.diff.highlight.added}
1110
+ removedSignColor={theme.diff.highlight.removed}
1111
+ lineNumberFg={theme.diff.lineNumber.text}
1112
+ lineNumberBg={theme.diff.background.context}
1113
+ addedLineNumberBg={theme.diff.lineNumber.background.added}
1114
+ removedLineNumberBg={theme.diff.lineNumber.background.removed}
1115
+ />
1116
+ )}
1117
+ </Match>
1118
+ </Switch>
1119
+ </Show>
1120
+ </box>
1121
+ </box>
1122
+ )
1123
+ }}
1124
+ </For>
1125
+ </scrollbox>
1126
+ </box>
1127
+ </box>
1128
+ </Match>
1129
+ </Switch>
1130
+ </box>
1131
+ <Show when={compact()}>
1132
+ {/* Docked, the footer sits on the terminal background, eased in by a half-cell like the prompt. */}
1133
+ <box id="diff-footer" flexShrink={0} backgroundColor={theme.background.base}>
1134
+ <Show when={docked()}>
1135
+ <box
1136
+ height={1}
1137
+ flexShrink={0}
1138
+ border={["bottom"]}
1139
+ borderColor={surface()}
1140
+ backgroundColor={theme.background.base}
1141
+ customBorderChars={{ ...EmptyBorder, horizontal: "▀" }}
1142
+ />
1143
+ </Show>
1144
+ <box height={1} flexShrink={0} flexDirection="row" paddingLeft={2} paddingRight={1}>
1145
+ <text
1146
+ fg={focused() ? theme.background.action.primary.focused : theme.text.action.primary.disabled}
1147
+ attributes={focused() ? 0 : TextAttributes.DIM}
1148
+ flexGrow={1}
1149
+ minWidth={0}
1150
+ wrapMode="none"
1151
+ truncate
1152
+ selectable={false}
1153
+ onMouseUp={(event) => {
1154
+ if (event.button !== MouseButton.LEFT) return
1155
+ if (!docked()) return close()
1156
+ if (!props.panel?.focused) props.panel?.focus()
1157
+ }}
1158
+ >
1159
+ {/* Without a prompt beside the viewer, closing is the way back to the session. */}
1160
+ <span>{props.context.keymap.shortcuts(docked() ? "pane.focus.left" : "diff.close")[0] ?? ""}</span>
1161
+ <span style={focused() ? { fg: theme.text.muted } : {}}>{docked() ? " focus prompt" : " close"}</span>
1162
+ </text>
1163
+ <box flexShrink={0}>
1164
+ <HelpShortcut label="see all" muted={!focused()} />
1165
+ </box>
1166
+ </box>
1167
+ <Show when={docked()}>
1168
+ <box height={1} flexShrink={0} />
1169
+ </Show>
1170
+ </box>
1171
+ </Show>
1172
+ <Show when={!showFileTree() && !compact()}>
1173
+ <box position="absolute" top={0} right={0} width={1} height={1}>
1174
+ <HelpShortcut compact />
1175
+ </box>
1176
+ </Show>
1177
+ <Show when={fileMenu()} keyed>
1178
+ {(state) => (
1179
+ <DiffFileMenu
1180
+ context={props.context}
1181
+ state={state}
1182
+ reviewed={reviewedFileNames().has(files()[state.fileIndex]?.file ?? "")}
1183
+ onToggle={() => toggleFileReviewed(state.fileIndex)}
1184
+ onClose={() => setFileMenu(undefined)}
1185
+ />
1186
+ )}
1187
+ </Show>
1188
+ </box>
1189
+ )
1190
+ }
1191
+
1192
+ /** A half-row of base background between cards: the card's color over its width, the pane surface in the insets. */
1193
+ function CardGap(props: { glyph: "▄" | "▀"; card: RGBA; surface: RGBA; inset: number }) {
1194
+ const theme = useTheme()
1195
+ const half = (color: RGBA, width?: number) => (
1196
+ <box
1197
+ height={1}
1198
+ flexShrink={0}
1199
+ {...(width === undefined ? { flexGrow: 1 } : { width })}
1200
+ border={[props.glyph === "▄" ? "top" : "bottom"]}
1201
+ borderColor={color}
1202
+ backgroundColor={theme.background.base}
1203
+ customBorderChars={{ ...EmptyBorder, horizontal: props.glyph }}
1204
+ />
1205
+ )
1206
+ return (
1207
+ <box height={1} flexShrink={0} flexDirection="row">
1208
+ {/* A zero-width inset still claims a cell, which would notch flush cards. */}
1209
+ <Show when={props.inset > 0}>{half(props.surface, props.inset)}</Show>
1210
+ {half(props.card)}
1211
+ <Show when={props.inset > 0}>{half(props.surface, props.inset)}</Show>
1212
+ </box>
1213
+ )
1214
+ }
1215
+
1216
+ function DiffViewerHelpDialog(props: { context: Plugin.Context; single: boolean; fullscreen: boolean; tree: boolean }) {
1217
+ const dimensions = useTerminalDimensions()
1218
+ const theme = props.context.theme.surface("dialog")
1219
+ const shortcut =
1220
+ (...ids: string[]) =>
1221
+ () =>
1222
+ ids
1223
+ .map((id) => props.context.keymap.shortcuts(id)[0])
1224
+ .filter(Boolean)
1225
+ .join(" / ")
1226
+ const groups = [
1227
+ {
1228
+ title: "Review",
1229
+ rows: [
1230
+ { shortcut: () => props.context.keymap.shortcuts("diff.next_file").join(" / "), label: "Next file" },
1231
+ { shortcut: () => props.context.keymap.shortcuts("diff.previous_file").join(" / "), label: "Previous file" },
1232
+ {
1233
+ shortcut: shortcut("diff.mark_reviewed"),
1234
+ label: props.single ? "Review + next / reopen" : "Review + collapse / reopen",
1235
+ },
1236
+ { shortcut: shortcut("diff.next_hunk", "diff.previous_hunk"), label: "Next / previous change" },
1237
+ { shortcut: () => "right-click", label: "File menu (heading or tree)" },
1238
+ ],
1239
+ },
1240
+ {
1241
+ title: "Scroll",
1242
+ rows: [
1243
+ { shortcut: shortcut("diff.down", "diff.up"), label: "Down / up" },
1244
+ { shortcut: shortcut("diff.half_page.down", "diff.half_page.up"), label: "Half page down / up" },
1245
+ { shortcut: shortcut("diff.page.down", "diff.page.up"), label: "Page down / up" },
1246
+ { shortcut: shortcut("diff.first", "diff.last"), label: "First / last" },
1247
+ ],
1248
+ },
1249
+ {
1250
+ title: "View",
1251
+ rows: [
1252
+ { shortcut: shortcut("diff.toggle_view"), label: "Split / unified" },
1253
+ { shortcut: shortcut("diff.single_patch"), label: "All files / single file" },
1254
+ ...(props.tree ? [{ shortcut: shortcut("diff.toggle_file_tree"), label: "Show / hide file tree" }] : []),
1255
+ { shortcut: shortcut("diff.switch_source"), label: "Switch diff source" },
1256
+ ...(props.fullscreen
1257
+ ? [{ shortcut: shortcut("diff.toggle_fullscreen"), label: "Full screen / split view" }]
1258
+ : []),
1259
+ { shortcut: () => props.context.keymap.shortcuts("diff.close").join(" / "), label: "Close diff viewer" },
1260
+ ],
1261
+ },
1262
+ ]
1263
+
1264
+ return (
1265
+ <DialogLayout
1266
+ header={
1267
+ <DialogHeader title="Diff shortcuts" closeLabel="esc close" onClose={() => props.context.ui.dialog.clear()} />
1268
+ }
1269
+ >
1270
+ <scrollbox
1271
+ id="diff-help-scroll"
1272
+ focused
1273
+ height={Math.max(
1274
+ 1,
1275
+ Math.min(
1276
+ dimensions().height - 6,
1277
+ groups.reduce((height, group) => height + group.rows.length + 2, -1),
1278
+ ),
1279
+ )}
1280
+ horizontalScrollbarOptions={{ visible: false }}
1281
+ verticalScrollbarOptions={{ visible: false }}
1282
+ >
1283
+ <box gap={1}>
1284
+ <For each={groups}>
1285
+ {(group) => (
1286
+ <box flexShrink={0}>
1287
+ <text fg={theme.text.base} attributes={TextAttributes.BOLD}>
1288
+ {group.title}
1289
+ </text>
1290
+ <For each={group.rows}>
1291
+ {(row) => (
1292
+ <box flexDirection="row" gap={2}>
1293
+ <text fg={theme.text.base} width={17} flexShrink={0}>
1294
+ {row.shortcut() || "unbound"}
1295
+ </text>
1296
+ <text fg={theme.text.muted} flexGrow={1} minWidth={0}>
1297
+ {row.label}
1298
+ </text>
1299
+ </box>
1300
+ )}
1301
+ </For>
1302
+ </box>
1303
+ )}
1304
+ </For>
1305
+ </box>
1306
+ </scrollbox>
1307
+ </DialogLayout>
1308
+ )
1309
+ }
1310
+
1311
+ function Commands(props: { context: Plugin.Context }) {
1312
+ const config = useConfig()
1313
+ props.context.keymap.layer(() => ({
1314
+ mode: "global",
1315
+ commands: [
1316
+ {
1317
+ id: "diff.open",
1318
+ title: "Open diff viewer",
1319
+ slash: { name: "diff" },
1320
+ group: "VCS",
1321
+ palette: true,
1322
+ run() {
1323
+ const route = props.context.ui.router.current()
1324
+ props.context.ui.dialog.clear()
1325
+ const current = props.context.ui.panel.current()
1326
+ if (route.type === "session" && current?.sessionID === route.sessionID && current.name === ROUTE) {
1327
+ props.context.ui.panel.close()
1328
+ return
1329
+ }
1330
+ // Outside a session there is no panel slot, so /diff falls back to the full-screen route.
1331
+ if (
1332
+ props.context.ui.panel.open(ROUTE, {
1333
+ presentation: config.data.diffs?.fullscreen === true ? "fullscreen" : "panel",
1334
+ })
1335
+ )
1336
+ return
1337
+ const returnRoute: Route =
1338
+ route.type === "home"
1339
+ ? { type: "home" }
1340
+ : route.type === "session"
1341
+ ? { type: "session", sessionID: route.sessionID }
1342
+ : {
1343
+ type: "plugin",
1344
+ id: route.id,
1345
+ name: route.name,
1346
+ ...(route.data ? { data: { ...route.data } } : {}),
1347
+ }
1348
+ props.context.ui.router.navigate({
1349
+ type: "plugin",
1350
+ name: ROUTE,
1351
+ data: {
1352
+ sessionID: route.type === "session" ? route.sessionID : undefined,
1353
+ returnRoute,
1354
+ },
1355
+ })
1356
+ },
1357
+ },
1358
+ ],
1359
+ }))
1360
+ return null
1361
+ }
1362
+
1363
+ export default Plugin.define({
1364
+ id: "opencode.diffs",
1365
+ setup(context) {
1366
+ context.ui.slot({
1367
+ append: "session.panel",
1368
+ render: (panel) => (
1369
+ <Show when={panel.name === ROUTE}>
1370
+ <DiffViewer context={context} sessionID={panel.sessionID} panel={panel} onClose={panel.close} />
1371
+ </Show>
1372
+ ),
1373
+ })
1374
+ context.ui.router.register({
1375
+ name: ROUTE,
1376
+ render: ({ data }) => <DiffRoute context={context} data={data} />,
1377
+ })
1378
+ context.ui.slot({ append: "app", render: () => <Commands context={context} /> })
1379
+ },
1380
+ })