@zyro-sec/tui 0.0.0-stage → 1.0.2
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.
- package/AGENTS.md +6 -0
- package/bunfig.toml +4 -0
- package/package.json +79 -4
- package/src/app.tsx +1632 -0
- package/src/assets/backgrounds/anime.png +0 -0
- package/src/assets/backgrounds/circuit.jpg +0 -0
- package/src/assets/backgrounds/cyber-grid.jpg +0 -0
- package/src/assets/backgrounds/datacenter.jpg +0 -0
- package/src/assets/backgrounds/hacker-desk.jpg +0 -0
- package/src/assets/backgrounds/matrix-code.jpg +0 -0
- package/src/attention-sounds.bun.ts +8 -0
- package/src/attention-sounds.node.ts +16 -0
- package/src/attention.ts +189 -0
- package/src/audio.d.ts +9 -0
- package/src/audio.ts +49 -0
- package/src/clipboard.ts +68 -0
- package/src/component/background-image.tsx +26 -0
- package/src/component/command-palette.tsx +74 -0
- package/src/component/devtools-bar.tsx +611 -0
- package/src/component/dialog-agent.tsx +33 -0
- package/src/component/dialog-background.tsx +102 -0
- package/src/component/dialog-config.tsx +494 -0
- package/src/component/dialog-debug.tsx +90 -0
- package/src/component/dialog-error-details.tsx +130 -0
- package/src/component/dialog-experiments.tsx +101 -0
- package/src/component/dialog-go-upsell.tsx +448 -0
- package/src/component/dialog-highlights.tsx +88 -0
- package/src/component/dialog-image-preview.tsx +85 -0
- package/src/component/dialog-install-mcp.tsx +67 -0
- package/src/component/dialog-integration.tsx +1332 -0
- package/src/component/dialog-mcp.tsx +184 -0
- package/src/component/dialog-model-free.tsx +79 -0
- package/src/component/dialog-model.tsx +238 -0
- package/src/component/dialog-open.tsx +509 -0
- package/src/component/dialog-pair.tsx +123 -0
- package/src/component/dialog-session-list.tsx +328 -0
- package/src/component/dialog-session-rename.tsx +37 -0
- package/src/component/dialog-shell-output.tsx +194 -0
- package/src/component/dialog-skill.tsx +93 -0
- package/src/component/dialog-speed.tsx +48 -0
- package/src/component/dialog-stash.tsx +90 -0
- package/src/component/dialog-status.tsx +50 -0
- package/src/component/dialog-theme-list.tsx +56 -0
- package/src/component/dialog-update.tsx +144 -0
- package/src/component/dialog-variant.tsx +43 -0
- package/src/component/dialog-workspace-file-changes.tsx +187 -0
- package/src/component/dialog-workspaces.tsx +413 -0
- package/src/component/dialog-worktree-name.tsx +40 -0
- package/src/component/error-component.tsx +258 -0
- package/src/component/fade-in-text.tsx +113 -0
- package/src/component/go-upsell-art.ts +338 -0
- package/src/component/logo.tsx +79 -0
- package/src/component/masked-text.ts +59 -0
- package/src/component/media-source.ts +43 -0
- package/src/component/migration-overlay.tsx +73 -0
- package/src/component/model-options.tsx +121 -0
- package/src/component/one-cell-spinner.tsx +75 -0
- package/src/component/panel-host.tsx +64 -0
- package/src/component/patch-diff.tsx +211 -0
- package/src/component/plugin-route-missing.tsx +21 -0
- package/src/component/prompt/autocomplete.tsx +1005 -0
- package/src/component/prompt/draft-stash.ts +47 -0
- package/src/component/prompt/index.tsx +2080 -0
- package/src/component/prompt/local-attachment.ts +188 -0
- package/src/component/prompt/metadata.tsx +193 -0
- package/src/component/prompt/move.tsx +181 -0
- package/src/component/reconnecting.tsx +40 -0
- package/src/component/retry-provider.tsx +202 -0
- package/src/component/session-frame.tsx +408 -0
- package/src/component/session-tabs-rail.tsx +94 -0
- package/src/component/session-tabs.tsx +1789 -0
- package/src/component/shimmer-text.tsx +64 -0
- package/src/component/spinner-frames.ts +1 -0
- package/src/component/spinner-renderable.ts +126 -0
- package/src/component/spinner.tsx +50 -0
- package/src/component/startup-loading.tsx +63 -0
- package/src/component/tab-pulse.tsx +819 -0
- package/src/component/terminal-pane.tsx +377 -0
- package/src/component/theme-error-toast.tsx +20 -0
- package/src/component/title-shimmer.tsx +272 -0
- package/src/component/todo-item.tsx +27 -0
- package/src/component/usage.tsx +329 -0
- package/src/component/use-connected.tsx +14 -0
- package/src/config/index.tsx +438 -0
- package/src/config/keybind.ts +367 -0
- package/src/config/new-session-location.ts +16 -0
- package/src/config/v1/index.tsx +149 -0
- package/src/config/v1/keybind.ts +463 -0
- package/src/context/args.tsx +31 -0
- package/src/context/attention.tsx +23 -0
- package/src/context/client-mcp.tsx +119 -0
- package/src/context/client.tsx +76 -0
- package/src/context/clipboard.tsx +19 -0
- package/src/context/data.tsx +69 -0
- package/src/context/editor.ts +408 -0
- package/src/context/epilogue.tsx +14 -0
- package/src/context/event.ts +32 -0
- package/src/context/exit.tsx +8 -0
- package/src/context/helper.tsx +26 -0
- package/src/context/interactivity.tsx +20 -0
- package/src/context/keymap.tsx +515 -0
- package/src/context/local.tsx +723 -0
- package/src/context/location.tsx +80 -0
- package/src/context/log.tsx +24 -0
- package/src/context/panel.tsx +59 -0
- package/src/context/path-format.tsx +12 -0
- package/src/context/permission.tsx +18 -0
- package/src/context/program-status.ts +94 -0
- package/src/context/prompt.tsx +18 -0
- package/src/context/route.tsx +73 -0
- package/src/context/runtime.tsx +98 -0
- package/src/context/session-tabs-model.ts +263 -0
- package/src/context/session-tabs.tsx +508 -0
- package/src/context/session-terminals.tsx +136 -0
- package/src/context/storage.tsx +150 -0
- package/src/context/theme.tsx +447 -0
- package/src/context/thinking.ts +20 -0
- package/src/context/update-notification.tsx +158 -0
- package/src/devtools/index.ts +41 -0
- package/src/editor-zed-sqlite.bun.ts +1 -0
- package/src/editor-zed-sqlite.node.ts +21 -0
- package/src/editor-zed.ts +277 -0
- package/src/editor.ts +86 -0
- package/src/feature-plugins/home/footer.tsx +116 -0
- package/src/feature-plugins/prompt/btw.tsx +190 -0
- package/src/feature-plugins/prompt/footer.tsx +163 -0
- package/src/feature-plugins/prompt/goal.tsx +211 -0
- package/src/feature-plugins/sidebar/context.tsx +52 -0
- package/src/feature-plugins/sidebar/footer.tsx +126 -0
- package/src/feature-plugins/sidebar/limit.tsx +47 -0
- package/src/feature-plugins/sidebar/mcp.tsx +103 -0
- package/src/feature-plugins/sidebar/todo.tsx +58 -0
- package/src/feature-plugins/system/diff-viewer-file-menu.tsx +87 -0
- package/src/feature-plugins/system/diff-viewer-file-tree-utils.ts +174 -0
- package/src/feature-plugins/system/diff-viewer-file-tree.tsx +274 -0
- package/src/feature-plugins/system/diff-viewer-image.tsx +96 -0
- package/src/feature-plugins/system/diff-viewer.tsx +1380 -0
- package/src/feature-plugins/system/notifications.ts +102 -0
- package/src/feature-plugins/system/plugins.tsx +356 -0
- package/src/feature-plugins/system/stats-data.ts +18 -0
- package/src/feature-plugins/system/stats.tsx +217 -0
- package/src/feature-plugins/system/storybook/footer.tsx +51 -0
- package/src/feature-plugins/system/storybook/highlights.tsx +71 -0
- package/src/feature-plugins/system/storybook/index.tsx +153 -0
- package/src/feature-plugins/system/storybook/link-clicks.tsx +125 -0
- package/src/feature-plugins/system/storybook/merman-layouts.tsx +200 -0
- package/src/feature-plugins/system/storybook/one-cell-spinner.fixtures.ts +144 -0
- package/src/feature-plugins/system/storybook/one-cell-spinner.tsx +293 -0
- package/src/feature-plugins/system/storybook/session-location-missing.tsx +80 -0
- package/src/feature-plugins/system/storybook/session-tabs.tsx +571 -0
- package/src/feature-plugins/system/storybook/subcell-spinner.fixtures.ts +115 -0
- package/src/feature-plugins/system/storybook/todo.tsx +166 -0
- package/src/index.tsx +2 -0
- package/src/logo.ts +21 -0
- package/src/mini/catalog.shared.ts +116 -0
- package/src/mini/demo.ts +1086 -0
- package/src/mini/entry.body.ts +244 -0
- package/src/mini/footer.command.tsx +1205 -0
- package/src/mini/footer.form.tsx +647 -0
- package/src/mini/footer.menu.tsx +313 -0
- package/src/mini/footer.permission.tsx +562 -0
- package/src/mini/footer.prompt.tsx +1533 -0
- package/src/mini/footer.subagent.tsx +268 -0
- package/src/mini/footer.ts +1193 -0
- package/src/mini/footer.view.tsx +1022 -0
- package/src/mini/footer.width.ts +118 -0
- package/src/mini/form.shared.ts +241 -0
- package/src/mini/index.ts +7 -0
- package/src/mini/mono.ts +277 -0
- package/src/mini/permission.shared.ts +199 -0
- package/src/mini/prompt.editor.ts +74 -0
- package/src/mini/prompt.shared.ts +192 -0
- package/src/mini/runtime.boot.ts +98 -0
- package/src/mini/runtime.lifecycle.ts +393 -0
- package/src/mini/runtime.queue.ts +320 -0
- package/src/mini/runtime.ts +1117 -0
- package/src/mini/scrollback.shared.ts +82 -0
- package/src/mini/scrollback.surface.ts +548 -0
- package/src/mini/scrollback.writer.tsx +380 -0
- package/src/mini/session-data.ts +13 -0
- package/src/mini/session.shared.ts +113 -0
- package/src/mini/splash.ts +307 -0
- package/src/mini/stream-v2.fragment.ts +83 -0
- package/src/mini/stream-v2.image.ts +38 -0
- package/src/mini/stream-v2.subagent.ts +1130 -0
- package/src/mini/stream-v2.transport.ts +1916 -0
- package/src/mini/stream.ts +152 -0
- package/src/mini/theme.ts +328 -0
- package/src/mini/tool.public.ts +3 -0
- package/src/mini/tool.ts +1394 -0
- package/src/mini/turn-summary.ts +21 -0
- package/src/mini/types.ts +482 -0
- package/src/mini/variant.shared.ts +58 -0
- package/src/mini/verbosity.ts +84 -0
- package/src/model-preference.ts +206 -0
- package/src/parsers-config.ts +386 -0
- package/src/plugin/api.tsx +486 -0
- package/src/plugin/builtins.ts +35 -0
- package/src/plugin/context.tsx +757 -0
- package/src/plugin/discovery.ts +67 -0
- package/src/plugin/markdown.ts +18 -0
- package/src/plugin/render.tsx +116 -0
- package/src/plugin/runtime-plugin-support.bun.ts +11 -0
- package/src/plugin/runtime-plugin-support.node.ts +1 -0
- package/src/plugin/source.ts +1 -0
- package/src/plugin/structure.ts +159 -0
- package/src/plugin/watch.ts +113 -0
- package/src/prompt/attachment.ts +97 -0
- package/src/prompt/codec.ts +61 -0
- package/src/prompt/content.ts +22 -0
- package/src/prompt/directory-completion.ts +97 -0
- package/src/prompt/directory-recents.ts +36 -0
- package/src/prompt/display.ts +41 -0
- package/src/prompt/frecency.tsx +80 -0
- package/src/prompt/history.tsx +175 -0
- package/src/prompt/mention.ts +173 -0
- package/src/prompt/parse.ts +25 -0
- package/src/prompt/part.ts +35 -0
- package/src/prompt/restore.ts +39 -0
- package/src/prompt/stash.tsx +93 -0
- package/src/prompt/traits.ts +29 -0
- package/src/routes/home.tsx +180 -0
- package/src/routes/session/activity-summary.ts +101 -0
- package/src/routes/session/anchor-view.tsx +53 -0
- package/src/routes/session/anchors.ts +85 -0
- package/src/routes/session/composer/context.ts +24 -0
- package/src/routes/session/composer/index.tsx +143 -0
- package/src/routes/session/composer/scripts-tab.tsx +166 -0
- package/src/routes/session/composer/shell-tab.tsx +149 -0
- package/src/routes/session/composer/subagents-tab.tsx +264 -0
- package/src/routes/session/composer/tabs.ts +91 -0
- package/src/routes/session/composer/terminals-tab.tsx +114 -0
- package/src/routes/session/dialog-execute.tsx +276 -0
- package/src/routes/session/dialog-fork.tsx +87 -0
- package/src/routes/session/dialog-message.tsx +89 -0
- package/src/routes/session/dialog-timeline.tsx +43 -0
- package/src/routes/session/form.tsx +1177 -0
- package/src/routes/session/group-view.tsx +407 -0
- package/src/routes/session/grouping/session.ts +184 -0
- package/src/routes/session/grouping/tree.ts +111 -0
- package/src/routes/session/history.ts +59 -0
- package/src/routes/session/index.tsx +3922 -0
- package/src/routes/session/location-missing.tsx +81 -0
- package/src/routes/session/message-navigation.ts +48 -0
- package/src/routes/session/message-parts.tsx +322 -0
- package/src/routes/session/mount-budget.ts +38 -0
- package/src/routes/session/permission.tsx +622 -0
- package/src/routes/session/render-context.tsx +44 -0
- package/src/routes/session/rows.ts +493 -0
- package/src/routes/session/sidebar.tsx +80 -0
- package/src/routes/session/thinking-syntax.ts +8 -0
- package/src/runtime.tsx +1 -0
- package/src/simulation/semantics.ts +12 -0
- package/src/theme/assets/aura.json +69 -0
- package/src/theme/assets/ayu.json +80 -0
- package/src/theme/assets/carbonfox.json +248 -0
- package/src/theme/assets/catppuccin-frappe.json +230 -0
- package/src/theme/assets/catppuccin-macchiato.json +230 -0
- package/src/theme/assets/catppuccin.json +112 -0
- package/src/theme/assets/cobalt2.json +225 -0
- package/src/theme/assets/cursor.json +249 -0
- package/src/theme/assets/dracula.json +219 -0
- package/src/theme/assets/everforest.json +241 -0
- package/src/theme/assets/flexoki.json +237 -0
- package/src/theme/assets/github.json +233 -0
- package/src/theme/assets/gruvbox.json +242 -0
- package/src/theme/assets/kanagawa.json +77 -0
- package/src/theme/assets/lucent-orng.json +234 -0
- package/src/theme/assets/material.json +235 -0
- package/src/theme/assets/matrix.json +77 -0
- package/src/theme/assets/mercury.json +252 -0
- package/src/theme/assets/monokai.json +221 -0
- package/src/theme/assets/nightowl.json +221 -0
- package/src/theme/assets/nord.json +223 -0
- package/src/theme/assets/one-dark.json +84 -0
- package/src/theme/assets/opencode.json +245 -0
- package/src/theme/assets/orng.json +249 -0
- package/src/theme/assets/osaka-jade.json +93 -0
- package/src/theme/assets/palenight.json +222 -0
- package/src/theme/assets/rosepine.json +234 -0
- package/src/theme/assets/solarized.json +223 -0
- package/src/theme/assets/synthwave84.json +226 -0
- package/src/theme/assets/tokyonight.json +243 -0
- package/src/theme/assets/v2/opencode-classic.json +387 -0
- package/src/theme/assets/v2/opencode.json +395 -0
- package/src/theme/assets/vercel.json +245 -0
- package/src/theme/assets/vesper.json +218 -0
- package/src/theme/assets/zenburn.json +223 -0
- package/src/theme/color.ts +48 -0
- package/src/theme/component.ts +51 -0
- package/src/theme/discovery.ts +21 -0
- package/src/theme/index.ts +109 -0
- package/src/theme/resolve.ts +53 -0
- package/src/theme/system.ts +144 -0
- package/src/theme/v1.ts +70 -0
- package/src/ui/animation.ts +235 -0
- package/src/ui/border.ts +21 -0
- package/src/ui/dialog-alert.tsx +51 -0
- package/src/ui/dialog-confirm.tsx +62 -0
- package/src/ui/dialog-export-options.tsx +316 -0
- package/src/ui/dialog-export-result.tsx +84 -0
- package/src/ui/dialog-help.tsx +40 -0
- package/src/ui/dialog-prompt.tsx +180 -0
- package/src/ui/dialog-select.tsx +1006 -0
- package/src/ui/dialog.tsx +560 -0
- package/src/ui/file-path.tsx +112 -0
- package/src/ui/layout.ts +26 -0
- package/src/ui/link.tsx +51 -0
- package/src/ui/one-cell-motion.ts +111 -0
- package/src/ui/pane-resize-handle.tsx +33 -0
- package/src/ui/pane-resize.ts +76 -0
- package/src/ui/select-controller.ts +45 -0
- package/src/ui/session-link.ts +92 -0
- package/src/ui/spinner.ts +368 -0
- package/src/ui/subcell.ts +37 -0
- package/src/ui/toast.tsx +222 -0
- package/src/ui/working-directory-actions.tsx +66 -0
- package/src/util/collapse-tool-output.ts +95 -0
- package/src/util/config-directories.ts +53 -0
- package/src/util/connected-provider.ts +15 -0
- package/src/util/delayed-presence.ts +34 -0
- package/src/util/diff.ts +84 -0
- package/src/util/error-details.ts +21 -0
- package/src/util/error.ts +141 -0
- package/src/util/filetype.ts +135 -0
- package/src/util/form.ts +146 -0
- package/src/util/highlights.ts +51 -0
- package/src/util/locale.ts +81 -0
- package/src/util/marquee.ts +51 -0
- package/src/util/media.ts +43 -0
- package/src/util/model.ts +33 -0
- package/src/util/path-format.ts +37 -0
- package/src/util/path.ts +12 -0
- package/src/util/permission.ts +188 -0
- package/src/util/persistence.ts +42 -0
- package/src/util/presentation.ts +42 -0
- package/src/util/project.ts +7 -0
- package/src/util/record.ts +3 -0
- package/src/util/renderer.ts +15 -0
- package/src/util/scroll.ts +29 -0
- package/src/util/selection.ts +103 -0
- package/src/util/session.ts +103 -0
- package/src/util/signal.ts +49 -0
- package/src/util/single-flight.ts +12 -0
- package/src/util/string-width.bun.ts +1 -0
- package/src/util/string-width.node.ts +26 -0
- package/src/util/string-width.ts +1 -0
- package/src/util/system.ts +23 -0
- package/src/util/todo.ts +43 -0
- package/src/util/tool-display.ts +70 -0
- package/src/util/usage-limits.ts +152 -0
- package/src/util/watch.ts +24 -0
- package/test/app-lifecycle.test.tsx +2962 -0
- package/test/clear-session.test.tsx +67 -0
- package/test/cli/cmd/tui/integration-options.test.ts +98 -0
- package/test/cli/cmd/tui/model-options.test.ts +105 -0
- package/test/cli/cmd/tui/notifications.test.ts +356 -0
- package/test/cli/tui/__snapshots__/inline-tool-wrap-snapshot.test.tsx.snap +22 -0
- package/test/cli/tui/anchors.test.ts +77 -0
- package/test/cli/tui/collapse-tool-output.test.ts +14 -0
- package/test/cli/tui/command-palette.test.tsx +86 -0
- package/test/cli/tui/composer-keymap.test.tsx +346 -0
- package/test/cli/tui/data.test.tsx +3669 -0
- package/test/cli/tui/dialog-integration.test.tsx +588 -0
- package/test/cli/tui/dialog-mcp.test.tsx +197 -0
- package/test/cli/tui/dialog-open.test.tsx +1037 -0
- package/test/cli/tui/dialog-prompt.test.tsx +253 -0
- package/test/cli/tui/dialog-select.test.tsx +740 -0
- package/test/cli/tui/dialog-session-list.test.tsx +130 -0
- package/test/cli/tui/diff-viewer-file-tree.test.tsx +256 -0
- package/test/cli/tui/diff-viewer-image.test.tsx +172 -0
- package/test/cli/tui/diff-viewer.test.tsx +2510 -0
- package/test/cli/tui/form.test.tsx +950 -0
- package/test/cli/tui/group-boundary.test.ts +63 -0
- package/test/cli/tui/group-view.test.tsx +352 -0
- package/test/cli/tui/grouping-tree.test.ts +82 -0
- package/test/cli/tui/inline-tool-wrap-snapshot.test.tsx +248 -0
- package/test/cli/tui/input-scope.test.tsx +282 -0
- package/test/cli/tui/keymap-arguments.test.tsx +45 -0
- package/test/cli/tui/message-navigation.test.ts +164 -0
- package/test/cli/tui/mount-budget.test.ts +74 -0
- package/test/cli/tui/permission.test.ts +7 -0
- package/test/cli/tui/plugins-dialog.test.tsx +217 -0
- package/test/cli/tui/prompt-interrupt-status.test.tsx +25 -0
- package/test/cli/tui/prompt-move.test.tsx +446 -0
- package/test/cli/tui/reasoning-body.test.tsx +80 -0
- package/test/cli/tui/script-changes.test.ts +41 -0
- package/test/cli/tui/session-grouping.test.ts +21 -0
- package/test/cli/tui/session-history.test.ts +124 -0
- package/test/cli/tui/session-rows.test.ts +616 -0
- package/test/cli/tui/session-verbosity.test.ts +307 -0
- package/test/cli/tui/theme-mode.test.tsx +179 -0
- package/test/cli/tui/thinking.test.ts +36 -0
- package/test/cli/tui/toast.test.tsx +117 -0
- package/test/cli/tui/use-event.test.tsx +295 -0
- package/test/client-mcp.test.tsx +226 -0
- package/test/clipboard.test.ts +148 -0
- package/test/command-selection.test.tsx +123 -0
- package/test/compact-admission.test.tsx +251 -0
- package/test/completion-notices.test.tsx +197 -0
- package/test/component/animation-ticks.test.tsx +212 -0
- package/test/component/dialog-error-details.test.tsx +110 -0
- package/test/component/dialog-export-options.test.tsx +68 -0
- package/test/component/dialog-highlights.test.tsx +73 -0
- package/test/component/dialog-model.test.tsx +145 -0
- package/test/component/dialog-shell-output.test.tsx +255 -0
- package/test/component/dialog-speed.test.tsx +114 -0
- package/test/component/dialog-update.test.tsx +111 -0
- package/test/component/dialog-variant.test.tsx +24 -0
- package/test/component/go-upsell-art.test.tsx +110 -0
- package/test/component/retry-provider.test.tsx +288 -0
- package/test/component/session-tabs-marquee.test.tsx +100 -0
- package/test/component/session-tabs-mouse.test.tsx +216 -0
- package/test/component/session-tabs-rail.test.tsx +120 -0
- package/test/component/session-tabs-status.test.tsx +345 -0
- package/test/component/shimmer-text.test.tsx +37 -0
- package/test/component/spinner-renderable.test.tsx +133 -0
- package/test/component/tab-pulse.test.tsx +196 -0
- package/test/component/terminal-pane-theme.test.ts +68 -0
- package/test/config-v2.test.tsx +335 -0
- package/test/config.test.tsx +184 -0
- package/test/context/local-selection.test.tsx +204 -0
- package/test/context/local.test.ts +15 -0
- package/test/context/program-status.test.ts +73 -0
- package/test/context/session-retention.test.ts +234 -0
- package/test/context/session-tabs-model.test.ts +341 -0
- package/test/context/session-tabs.test.tsx +864 -0
- package/test/context/storage.test.ts +37 -0
- package/test/context/theme.test.tsx +183 -0
- package/test/copy-session-id.test.tsx +79 -0
- package/test/editor.test.ts +69 -0
- package/test/feature-plugins/diff-viewer-file-tree-utils.test.ts +234 -0
- package/test/feature-plugins/goal.test.tsx +126 -0
- package/test/feature-plugins/home-footer.test.ts +13 -0
- package/test/feature-plugins/prompt-footer.test.tsx +303 -0
- package/test/feature-plugins/sidebar-context.test.tsx +70 -0
- package/test/feature-plugins/sidebar-footer.test.tsx +139 -0
- package/test/fixture/animation-ticks.ts +19 -0
- package/test/fixture/app.ts +95 -0
- package/test/fixture/diff-image.ts +7 -0
- package/test/fixture/fixture.ts +27 -0
- package/test/fixture/frame.ts +25 -0
- package/test/fixture/local.tsx +158 -0
- package/test/fixture/plugin/client-reads/tui.tsx +9 -0
- package/test/fixture/plugin/dialog-throw/tui.tsx +11 -0
- package/test/fixture/plugin/native-resources/tui.tsx +26 -0
- package/test/fixture/plugin/setup-keymap/tui.tsx +72 -0
- package/test/fixture/plugin/slot-string/tui.tsx +10 -0
- package/test/fixture/tui-client.ts +186 -0
- package/test/fixture/tui-environment.tsx +47 -0
- package/test/fixture/tui-runtime.ts +21 -0
- package/test/highlights.test.ts +43 -0
- package/test/interactivity.test.tsx +46 -0
- package/test/keybind.test.ts +7 -0
- package/test/keymap-scope.test.tsx +271 -0
- package/test/keymap.test.tsx +244 -0
- package/test/markdown-streaming.test.tsx +49 -0
- package/test/mini/blocker.responsive.test.tsx +732 -0
- package/test/mini/catalog.shared.test.ts +76 -0
- package/test/mini/entry.body.test.ts +622 -0
- package/test/mini/fixture/catalog.ts +63 -0
- package/test/mini/fixture/footer-api.ts +69 -0
- package/test/mini/fixture/tool-part.ts +20 -0
- package/test/mini/footer-keymap.test.tsx +141 -0
- package/test/mini/footer.menu.test.ts +43 -0
- package/test/mini/footer.responsive.test.tsx +438 -0
- package/test/mini/footer.test.ts +446 -0
- package/test/mini/footer.view.test.tsx +2627 -0
- package/test/mini/footer.width.test.ts +120 -0
- package/test/mini/form.shared.test.ts +66 -0
- package/test/mini/permission.shared.test.ts +195 -0
- package/test/mini/prompt.editor.test.ts +118 -0
- package/test/mini/prompt.shared.test.ts +104 -0
- package/test/mini/runtime.boot.test.ts +118 -0
- package/test/mini/runtime.queue.test.ts +443 -0
- package/test/mini/runtime.test.ts +591 -0
- package/test/mini/scrollback.image.test.ts +213 -0
- package/test/mini/scrollback.surface.test.ts +1078 -0
- package/test/mini/session.shared.test.ts +267 -0
- package/test/mini/splash.test.ts +196 -0
- package/test/mini/stream-v2.transport.test.ts +4705 -0
- package/test/mini/stream.test.ts +52 -0
- package/test/mini/theme.test.ts +438 -0
- package/test/mini/tool.test.ts +134 -0
- package/test/mini/variant.shared.test.ts +58 -0
- package/test/mini/verbosity.test.ts +53 -0
- package/test/model-preference.test.ts +70 -0
- package/test/new-session-id.test.tsx +102 -0
- package/test/new-session-location.test.ts +30 -0
- package/test/panel.test.ts +71 -0
- package/test/plugin-discovery.test.ts +18 -0
- package/test/plugin-keymap.test.tsx +143 -0
- package/test/plugin-markdown.test.tsx +120 -0
- package/test/plugin-model.test.tsx +46 -0
- package/test/plugin-native-resources.test.tsx +11 -0
- package/test/plugin-select.test.tsx +391 -0
- package/test/plugin-slot-output.test.tsx +23 -0
- package/test/plugin-source.test.ts +871 -0
- package/test/plugin-toast.test.tsx +62 -0
- package/test/preload.ts +17 -0
- package/test/prompt/attachment.test.ts +138 -0
- package/test/prompt/autocomplete.test.ts +218 -0
- package/test/prompt/codec.test.ts +136 -0
- package/test/prompt/display.test.ts +72 -0
- package/test/prompt/draft-stash.test.ts +42 -0
- package/test/prompt/history-composer.test.tsx +52 -0
- package/test/prompt/history-provider.test.tsx +108 -0
- package/test/prompt/history.test.ts +94 -0
- package/test/prompt/jsonl.test.ts +24 -0
- package/test/prompt/local-attachment.test.ts +244 -0
- package/test/prompt/mention.test.ts +119 -0
- package/test/prompt/parse.test.ts +46 -0
- package/test/prompt/part.test.ts +40 -0
- package/test/prompt/persistence.test.ts +23 -0
- package/test/prompt/traits.test.ts +25 -0
- package/test/prompt-cursor.test.tsx +27 -0
- package/test/prompt-offset.test.tsx +58 -0
- package/test/prompt-paste.test.tsx +127 -0
- package/test/prompt-shell-failure.test.tsx +76 -0
- package/test/routes/composer-tabs.test.tsx +97 -0
- package/test/runtime.test.tsx +37 -0
- package/test/session-activity-anchor.test.tsx +180 -0
- package/test/session-backfill-disclosure.test.tsx +89 -0
- package/test/session-dialog-resync.test.tsx +122 -0
- package/test/session-fork-pending.test.tsx +60 -0
- package/test/session-group-navigation.test.tsx +252 -0
- package/test/session-history-interactions.test.tsx +305 -0
- package/test/session-history-reveal.test.tsx +108 -0
- package/test/session-home.test.tsx +401 -0
- package/test/session-interrupt-undo.test.tsx +98 -0
- package/test/session-media-refs.test.tsx +360 -0
- package/test/session-mount-budget.test.tsx +137 -0
- package/test/session-panel.test.tsx +721 -0
- package/test/session-shell-output.test.tsx +114 -0
- package/test/session-shell-stopped.test.tsx +107 -0
- package/test/session-subagent-navigation.test.tsx +44 -0
- package/test/session-submit-scroll.test.tsx +85 -0
- package/test/session-terminal-availability.test.tsx +80 -0
- package/test/session-wheel-focus.test.tsx +176 -0
- package/test/simulation/semantics.test.ts +23 -0
- package/test/stats.test.ts +33 -0
- package/test/stats.view.test.tsx +94 -0
- package/test/theme/v2/component.test.ts +87 -0
- package/test/theme/v2/resolve.test.ts +424 -0
- package/test/theme/v2/select.test.ts +25 -0
- package/test/theme/v2/types.typecheck.ts +57 -0
- package/test/theme/v2/v1-migrate.test.ts +397 -0
- package/test/theme.test.ts +150 -0
- package/test/ui/dialog-layout.test.tsx +56 -0
- package/test/ui/file-path.test.ts +61 -0
- package/test/ui/layout.test.ts +31 -0
- package/test/ui/link.test.tsx +60 -0
- package/test/ui/pane-resize-handle.test.tsx +134 -0
- package/test/ui/pane-resize.test.ts +258 -0
- package/test/ui/select-controller.test.ts +44 -0
- package/test/ui/session-link.test.tsx +325 -0
- package/test/usage-limits.test.tsx +162 -0
- package/test/util/added-patch.test.ts +44 -0
- package/test/util/connected-provider.test.ts +59 -0
- package/test/util/delayed-presence.test.ts +114 -0
- package/test/util/error-details.test.ts +26 -0
- package/test/util/error.test.ts +36 -0
- package/test/util/filetype.test.ts +23 -0
- package/test/util/form.test.ts +110 -0
- package/test/util/locale.test.ts +32 -0
- package/test/util/marquee.test.ts +45 -0
- package/test/util/media.test.ts +54 -0
- package/test/util/model.test.ts +70 -0
- package/test/util/path-format.test.ts +15 -0
- package/test/util/permission.test.ts +23 -0
- package/test/util/presentation.test.ts +30 -0
- package/test/util/renderer.test.ts +42 -0
- package/test/util/selection-copy-on-select.test.tsx +64 -0
- package/test/util/selection-keys.test.ts +172 -0
- package/test/util/selection.test.ts +115 -0
- package/test/util/session.test.ts +70 -0
- package/test/util/tool-display.test.ts +65 -0
- package/test/util/usage-limits.test.ts +154 -0
- package/tsconfig.json +13 -0
- package/README.md +0 -3
|
@@ -0,0 +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
|
+
})
|