Skip to content

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

TypeScript

mods/diff: a close ✕ at the header's right edge closes the pane as /diff does

poteat8b41514793d8
diff --git a/mods/diff/hooks/register.ts b/mods/diff/hooks/register.ts
index 18c90f0e..8033d8bf 100644
--- a/mods/diff/hooks/register.ts
+++ b/mods/diff/hooks/register.ts
@@ -400,6 +400,11 @@ export function register(on: On) {
arm(engine, path)
},
+ close: () => {
+ void closePane(engine)
+ .then(() => engine.storeSet(Names.STORE_OPEN_KEY, false))
+ .catch(() => undefined)
+ },
})
function arm(engine: Host, path: string) {
diff --git a/mods/diff/hooks/views/pane-actions/pane-actions.ts b/mods/diff/hooks/views/pane-actions/pane-actions.ts
index a66c943d..5e505dd5 100644
--- a/mods/diff/hooks/views/pane-actions/pane-actions.ts
+++ b/mods/diff/hooks/views/pane-actions/pane-actions.ts
@@ -33,4 +33,10 @@ export type PaneActions = {
* Arms this file's diff for the next prompt, or disarms it.
*/
toggleAsk: (path: string) => void
+
+ /**
+ * Closes the pane as `/diff` closes it, the choice kept for the next
+ * first edit.
+ */
+ close: () => void
}
diff --git a/mods/diff/hooks/views/sections/close-button/close-button.tsx b/mods/diff/hooks/views/sections/close-button/close-button.tsx
new file mode 100644
index 00000000..3a8cc7fc
--- /dev/null
+++ b/mods/diff/hooks/views/sections/close-button/close-button.tsx
@@ -0,0 +1,33 @@
+/* @jsxRuntime classic */
+/* @jsx h */
+/* @jsxFrag Fragment */
+import type { RenderElement } from 'claude-code'
+
+import type { Kit } from '../../kit'
+
+/**
+ * The pane's close control (ReplDiffSidebar's PanelCloseButton): a `✕` at
+ * the header's right edge that closes the pane as `/diff` does.
+ *
+ * Bold under the pointer, as the built-in's is. The built-in's rest style,
+ * dim, is not a Button's to take: its label's only style is `hover`.
+ *
+ * @param kit the drawing's kit; its handlers close the pane
+ * @returns the control, in the keyed Box its hover needs
+ */
+export function closeButton(kit: Kit): RenderElement {
+ const { Box, Button } = kit.ui
+
+ return (
+ <Box key="close">
+ <Button
+ key="close"
+ plain
+ hover={{ bold: true }}
+ onPress={kit.actions.close}
+ >
+ {'✕'}
+ </Button>
+ </Box>
+ )
+}
diff --git a/mods/diff/hooks/views/sections/close-button/index.ts b/mods/diff/hooks/views/sections/close-button/index.ts
new file mode 100644
index 00000000..92f8d806
--- /dev/null
+++ b/mods/diff/hooks/views/sections/close-button/index.ts
@@ -0,0 +1,3 @@
+export * from './close-button.jsx'
+
+export * as default from '.'
diff --git a/mods/diff/hooks/views/sections/header-view.tsx b/mods/diff/hooks/views/sections/header-view.tsx
index b69bf9f5..86fa6716 100644
--- a/mods/diff/hooks/views/sections/header-view.tsx
+++ b/mods/diff/hooks/views/sections/header-view.tsx
@@ -6,11 +6,13 @@ import type { RenderElement } from 'claude-code'
import type PaneState from '../../pane-state'
import type { Kit } from '../kit'
import Layout from '../layout'
+import { closeButton } from './close-button'
import { diffStat } from './diff-stat'
/**
- * The pane's first line: `N files changed +A -R`, or the empty headline in
- * its place when there is nothing to count (ReplDiffSidebar's header).
+ * The pane's first line (ReplDiffSidebar's header row): `N files changed
+ * +A -R`, or the empty headline in its place when there is nothing to
+ * count, and the close `✕` at the right edge either way.
*
* The headline may name a branch the repository chose, so it is drawn as
* a name: no control or format character survives.
@@ -25,7 +27,7 @@ export function headerView(
headline: string | null,
totals: PaneState.HeaderTotals,
): RenderElement {
- const { Text } = kit.ui
+ const { Box, Text } = kit.ui
const empty = (
<Text dimColor wrap="truncate-end">
{Layout.sanitizeName(headline ?? '')}
@@ -39,5 +41,9 @@ export function headerView(
</Text>
)
- return headline === null ? counts : empty
+ return (
+ <Box flexDirection="row">
+ {[headline === null ? counts : empty, <Box flexGrow={1} />, closeButton(kit)]}
+ </Box>
+ )
}
diff --git a/mods/diff/hooks/views/sections/index.ts b/mods/diff/hooks/views/sections/index.ts
index fd97560d..8e8c4c46 100644
--- a/mods/diff/hooks/views/sections/index.ts
+++ b/mods/diff/hooks/views/sections/index.ts
@@ -1,3 +1,4 @@
+export * from './close-button'
export * from './controls-view.jsx'
export * from './diff-stat'
export * from './dim-note'