fix(tui): make undo inclusive of last user message and simplify revert banner

This commit is contained in:
Dax Raad 2026-06-27 20:25:08 -04:00
parent f4720be08e
commit 49e7dc191f
2 changed files with 42 additions and 5 deletions

View file

@ -878,7 +878,8 @@ export function Session() {
</For>
<Show when={session()?.revert?.messageID}>
<RevertMessage
count={messages().filter((message) => message.id > session()!.revert!.messageID).length}
count={messages().filter((message) => message.id >= session()!.revert!.messageID && message.type === "user").length}
files={session()!.revert!.files ?? []}
/>
</Show>
</scrollbox>
@ -1167,7 +1168,21 @@ function CompactionMessage() {
)
}
function RevertMessage(props: { count: number }) {
function statusLabel(status: "added" | "modified" | "deleted") {
if (status === "added") return "A"
if (status === "deleted") return "D"
return "M"
}
function RevertMessage(props: {
count: number
files: ReadonlyArray<{
readonly path: string
readonly status: "added" | "modified" | "deleted"
readonly additions: number
readonly deletions: number
}>
}) {
const { theme } = useTheme()
const route = useRouteData("session")
const sdk = useSDK()
@ -1186,13 +1201,35 @@ function RevertMessage(props: { count: number }) {
})()
}}
flexShrink={0}
marginTop={1}
border={["left"]}
customBorderChars={SplitBorder.customBorderChars}
borderColor={theme.backgroundPanel}
>
<box paddingTop={1} paddingBottom={1} paddingLeft={2} backgroundColor={hover() ? theme.backgroundElement : theme.backgroundPanel}>
<text fg={theme.textMuted}>{props.count} message{props.count === 1 ? "" : "s"} reverted</text>
<text fg={theme.textMuted}>Click to redo</text>
<text fg={theme.textMuted}>
{props.count} message{props.count === 1 ? "" : "s"} reverted
</text>
<Show when={props.files.length > 0}>
<box marginTop={1} flexDirection="column">
<For each={props.files}>
{(file) => (
<box flexDirection="row" gap={1} flexShrink={0}>
<text fg={theme.textMuted}>{statusLabel(file.status)}</text>
<text fg={theme.text} wrapMode="none">
{Locale.truncateLeft(file.path, 60)}
</text>
<Show when={file.additions > 0}>
<text fg={theme.diffAdded}>+{file.additions}</text>
</Show>
<Show when={file.deletions > 0}>
<text fg={theme.diffRemoved}>-{file.deletions}</text>
</Show>
</box>
)}
</For>
</box>
</Show>
</box>
</box>
)

View file

@ -28,7 +28,7 @@ export function createSessionRows(sessionID: Accessor<string>) {
function reduce() {
const messages = data.session.message.list(sessionID())
const boundary = revertBoundary()
return reduceSessionRows(boundary ? messages.filter((message) => message.id <= boundary) : messages)
return reduceSessionRows(boundary ? messages.filter((message) => message.id < boundary) : messages)
}
createEffect(() => {