mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
sync
This commit is contained in:
parent
cd74c6eeea
commit
7844ab9855
1 changed files with 37 additions and 11 deletions
|
|
@ -28,6 +28,7 @@ import { useCommandDialog } from "@tui/component/dialog-command"
|
|||
import { Shimmer } from "@tui/ui/shimmer"
|
||||
import { useKeybind } from "@tui/context/keybind"
|
||||
import { Header } from "./header"
|
||||
import { parsePatch } from "diff"
|
||||
|
||||
export function Session() {
|
||||
const route = useRouteData("session")
|
||||
|
|
@ -161,18 +162,34 @@ export function Session() {
|
|||
},
|
||||
])
|
||||
|
||||
const revert = createMemo(() => {
|
||||
const s = session()
|
||||
if (!s) return
|
||||
const messageID = s.revert?.messageID
|
||||
if (!messageID) return
|
||||
const reverted = messages().filter((x) => x.id >= messageID && x.role === "user")
|
||||
const revert = createMemo(() => {
|
||||
const s = session()
|
||||
if (!s) return
|
||||
const messageID = s.revert?.messageID
|
||||
if (!messageID) return
|
||||
const reverted = messages().filter((x) => x.id >= messageID && x.role === "user")
|
||||
|
||||
return {
|
||||
messageID,
|
||||
reverted,
|
||||
}
|
||||
})
|
||||
const diffFiles = (() => {
|
||||
const diffText = s.revert?.diff || ""
|
||||
if (!diffText) return []
|
||||
|
||||
const patches = parsePatch(diffText)
|
||||
return patches.map(patch => ({
|
||||
filename: patch.oldFileName || patch.newFileName || 'unknown',
|
||||
additions: patch.hunks.reduce((sum, hunk) =>
|
||||
sum + hunk.lines.filter(line => line.startsWith('+')).length, 0),
|
||||
deletions: patch.hunks.reduce((sum, hunk) =>
|
||||
sum + hunk.lines.filter(line => line.startsWith('-')).length, 0)
|
||||
}))
|
||||
})()
|
||||
|
||||
return {
|
||||
messageID,
|
||||
reverted,
|
||||
diff: s.revert!.diff,
|
||||
diffFiles,
|
||||
}
|
||||
})
|
||||
|
||||
return (
|
||||
<box paddingTop={1} paddingBottom={1} paddingLeft={2} paddingRight={2} flexGrow={1}>
|
||||
|
|
@ -203,6 +220,15 @@ export function Session() {
|
|||
<text fg={Theme.textMuted}>
|
||||
<span style={{ fg: Theme.text }}>{keybind.print("messages_redo")}</span> or /redo to restore
|
||||
</text>
|
||||
<Show when={revert()!.diffFiles?.length}>
|
||||
<For each={revert()!.diffFiles}>
|
||||
{(file) => (
|
||||
<text fg={Theme.textMuted}>
|
||||
{file.filename}: +{file.additions} -{file.deletions}
|
||||
</text>
|
||||
)}
|
||||
</For>
|
||||
</Show>
|
||||
</box>
|
||||
</box>
|
||||
</Match>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue