fix padding

This commit is contained in:
James Long 2026-05-20 10:32:09 -04:00
commit 53e2ab8b1f

View file

@ -73,7 +73,10 @@ function DiffViewer(props: { api: TuiPluginApi }) {
if (input.mode === "last-turn") { if (input.mode === "last-turn") {
const sessionID = input.sessionID const sessionID = input.sessionID
if (!sessionID) return [] if (!sessionID) return []
const result = await props.api.client.session.diff({ sessionID, messageID: input.messageID }, { throwOnError: true }) const result = await props.api.client.session.diff(
{ sessionID, messageID: input.messageID },
{ throwOnError: true },
)
return normalizeDiffs(result.data ?? []) return normalizeDiffs(result.data ?? [])
} }
@ -121,7 +124,10 @@ function DiffViewer(props: { api: TuiPluginApi }) {
const highlighted = highlightedFileNode() const highlighted = highlightedFileNode()
if (highlighted !== undefined && fileRows().some((row) => row.id === highlighted)) return if (highlighted !== undefined && fileRows().some((row) => row.id === highlighted)) return
const lastHighlighted = lastHighlightedFileNode() const lastHighlighted = lastHighlightedFileNode()
const next = lastHighlighted !== undefined && fileRows().some((row) => row.id === lastHighlighted) ? lastHighlighted : fileRows()[0]?.id const next =
lastHighlighted !== undefined && fileRows().some((row) => row.id === lastHighlighted)
? lastHighlighted
: fileRows()[0]?.id
setHighlightedFileNode(next) setHighlightedFileNode(next)
} }
@ -130,7 +136,8 @@ function DiffViewer(props: { api: TuiPluginApi }) {
if (node !== undefined) setLastHighlightedFileNode(node) if (node !== undefined) setLastHighlightedFileNode(node)
} }
const moveFileSelection = (offset: number) => setHighlighted(moveFileTreeSelection(fileRows(), highlightedFileNode(), offset)) const moveFileSelection = (offset: number) =>
setHighlighted(moveFileTreeSelection(fileRows(), highlightedFileNode(), offset))
const clearFileTreePatchState = () => { const clearFileTreePatchState = () => {
setHighlightedFileNode(undefined) setHighlightedFileNode(undefined)
@ -182,14 +189,17 @@ function DiffViewer(props: { api: TuiPluginApi }) {
const jumpRelativePatchFile = (offset: number) => { const jumpRelativePatchFile = (offset: number) => {
const current = focus() === "files" ? highlightedFileNode() : undefined const current = focus() === "files" ? highlightedFileNode() : undefined
const nextFromSelection = current === undefined ? undefined : moveFileTreeSelectionToFile(fileRows(), current, offset) const nextFromSelection =
current === undefined ? undefined : moveFileTreeSelectionToFile(fileRows(), current, offset)
if (nextFromSelection !== undefined) { if (nextFromSelection !== undefined) {
jumpToFileIndex(fileRows().find((row) => row.id === nextFromSelection)?.fileIndex) jumpToFileIndex(fileRows().find((row) => row.id === nextFromSelection)?.fileIndex)
return return
} }
const currentFileIndex = activePatchFileIndex() ?? currentPatchFileIndex() const currentFileIndex = activePatchFileIndex() ?? currentPatchFileIndex()
const currentRow = fileRows().find((row) => row.fileIndex === currentFileIndex) const currentRow = fileRows().find((row) => row.fileIndex === currentFileIndex)
scrollToFileIndex(fileRows().find((row) => row.id === moveFileTreeSelectionToFile(fileRows(), currentRow?.id, offset))?.fileIndex) scrollToFileIndex(
fileRows().find((row) => row.id === moveFileTreeSelectionToFile(fileRows(), currentRow?.id, offset))?.fileIndex,
)
} }
const highlightedPatchFileIndex = () => fileRows().find((row) => row.id === highlightedFileNode())?.fileIndex const highlightedPatchFileIndex = () => fileRows().find((row) => row.id === highlightedFileNode())?.fileIndex
@ -316,7 +326,9 @@ function DiffViewer(props: { api: TuiPluginApi }) {
category: "VCS", category: "VCS",
run: focusRunner({ run: focusRunner({
files() { files() {
setExpandedFileNodes((expanded) => setFileTreeDirectoryExpanded(fileTree(), expanded, highlightedFileNode(), true)) setExpandedFileNodes((expanded) =>
setFileTreeDirectoryExpanded(fileTree(), expanded, highlightedFileNode(), true),
)
}, },
patches() {}, patches() {},
}), }),
@ -327,7 +339,9 @@ function DiffViewer(props: { api: TuiPluginApi }) {
category: "VCS", category: "VCS",
run: focusRunner({ run: focusRunner({
files() { files() {
setExpandedFileNodes((expanded) => setFileTreeDirectoryExpanded(fileTree(), expanded, highlightedFileNode(), false)) setExpandedFileNodes((expanded) =>
setFileTreeDirectoryExpanded(fileTree(), expanded, highlightedFileNode(), false),
)
}, },
patches() {}, patches() {},
}), }),
@ -505,10 +519,14 @@ function DiffViewer(props: { api: TuiPluginApi }) {
> >
<Switch> <Switch>
<Match when={diff.error}> <Match when={diff.error}>
<box paddingTop={1}>
<text fg={theme().error}>Failed to load diff</text> <text fg={theme().error}>Failed to load diff</text>
</box>
</Match> </Match>
<Match when={files().length === 0}> <Match when={files().length === 0}>
<box paddingTop={1}>
<text fg={theme().textMuted}>No diff to show</text> <text fg={theme().textMuted}>No diff to show</text>
</box>
</Match> </Match>
<Match when={files().length > 0}> <Match when={files().length > 0}>
<scrollbox <scrollbox
@ -539,7 +557,10 @@ function DiffViewer(props: { api: TuiPluginApi }) {
<text fg={theme().diffAdded}>+{entry.file.additions}</text> <text fg={theme().diffAdded}>+{entry.file.additions}</text>
<text fg={theme().diffRemoved}>-{entry.file.deletions}</text> <text fg={theme().diffRemoved}>-{entry.file.deletions}</text>
</box> </box>
<Show when={entry.file.patch} fallback={<text fg={theme().textMuted}>No patch available for this file.</text>}> <Show
when={entry.file.patch}
fallback={<text fg={theme().textMuted}>No patch available for this file.</text>}
>
{(patch) => ( {(patch) => (
<diff <diff
diff={patch()} diff={patch()}
@ -598,14 +619,16 @@ function DiffViewer(props: { api: TuiPluginApi }) {
<Show when={toggleFileTreeShortcut()}> <Show when={toggleFileTreeShortcut()}>
{(shortcut) => ( {(shortcut) => (
<text fg={theme().text}> <text fg={theme().text}>
{shortcut()} <span style={{ fg: theme().textMuted }}>{showFileTree() ? "hide file tree" : "show file tree"}</span> {shortcut()}{" "}
<span style={{ fg: theme().textMuted }}>{showFileTree() ? "hide file tree" : "show file tree"}</span>
</text> </text>
)} )}
</Show> </Show>
<Show when={singlePatchShortcut()}> <Show when={singlePatchShortcut()}>
{(shortcut) => ( {(shortcut) => (
<text fg={theme().text}> <text fg={theme().text}>
{shortcut()} <span style={{ fg: theme().textMuted }}>{singlePatch() ? "all patches" : "single patch"}</span> {shortcut()}{" "}
<span style={{ fg: theme().textMuted }}>{singlePatch() ? "all patches" : "single patch"}</span>
</text> </text>
)} )}
</Show> </Show>
@ -619,7 +642,8 @@ function DiffViewer(props: { api: TuiPluginApi }) {
<Show when={toggleViewShortcut()}> <Show when={toggleViewShortcut()}>
{(shortcut) => ( {(shortcut) => (
<text fg={theme().text}> <text fg={theme().text}>
{shortcut()} <span style={{ fg: theme().textMuted }}>{view() === "split" ? "unified view" : "split view"}</span> {shortcut()}{" "}
<span style={{ fg: theme().textMuted }}>{view() === "split" ? "unified view" : "split view"}</span>
</text> </text>
)} )}
</Show> </Show>