mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-21 18:26:09 +00:00
fix(tui): pass prompt setter to revert dialog
This commit is contained in:
committed by
𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
parent
88cc5cb1bc
commit
71be35f7a0
@@ -6,15 +6,18 @@ import { useToast } from "../../ui/toast"
|
||||
import { useSDK } from "../../context/sdk"
|
||||
import { errorMessage } from "../../util/error"
|
||||
import { DialogFork } from "./dialog-fork"
|
||||
import { usePromptRef } from "../../context/prompt"
|
||||
import { revertedPrompt } from "../../util/revert-prompt"
|
||||
import type { PromptInfo } from "../../prompt/history"
|
||||
|
||||
export function DialogMessage(props: { messageID: string; sessionID: string }) {
|
||||
export function DialogMessage(props: {
|
||||
messageID: string
|
||||
sessionID: string
|
||||
setPrompt?: (prompt: PromptInfo) => void
|
||||
}) {
|
||||
const data = useData()
|
||||
const clipboard = useClipboard()
|
||||
const toast = useToast()
|
||||
const sdk = useSDK()
|
||||
const promptRef = usePromptRef()
|
||||
const message = createMemo(() => data.session.message.get(props.sessionID, props.messageID))
|
||||
|
||||
return (
|
||||
@@ -27,7 +30,7 @@ export function DialogMessage(props: { messageID: string; sessionID: string }) {
|
||||
description: "undo messages and file changes",
|
||||
onSelect: (dialog) => {
|
||||
const value = message()
|
||||
if (value?.type === "user") promptRef.current?.set(revertedPrompt(value))
|
||||
if (value?.type === "user") props.setPrompt?.(revertedPrompt(value))
|
||||
void sdk.api.session.revert
|
||||
.stage({ sessionID: props.sessionID, messageID: props.messageID })
|
||||
.catch((error) => toast.show({ message: errorMessage(error), variant: "error", duration: 5000 }))
|
||||
|
||||
@@ -1465,6 +1465,7 @@ function UserMessage(props: { message: SessionMessageUser }) {
|
||||
)
|
||||
const dialog = useDialog()
|
||||
const renderer = useRenderer()
|
||||
const promptRef = usePromptRef()
|
||||
|
||||
return (
|
||||
<Show when={props.message.text.trim() || files().length}>
|
||||
@@ -1483,7 +1484,13 @@ function UserMessage(props: { message: SessionMessageUser }) {
|
||||
}}
|
||||
onMouseUp={() => {
|
||||
if (renderer.getSelection()?.getSelectedText()) return
|
||||
dialog.replace(() => <DialogMessage messageID={props.message.id} sessionID={ctx.sessionID} />)
|
||||
dialog.replace(() => (
|
||||
<DialogMessage
|
||||
messageID={props.message.id}
|
||||
sessionID={ctx.sessionID}
|
||||
setPrompt={(value) => promptRef.current?.set(value)}
|
||||
/>
|
||||
))
|
||||
}}
|
||||
paddingTop={1}
|
||||
paddingBottom={1}
|
||||
|
||||
Reference in New Issue
Block a user