Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions webview-ui/src/components/chat/ChatRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ export const ChatRowContent = ({
<span style={{ fontWeight: "bold" }}>{t("chat:text.rooSaid")}</span>
</div>
<div className="pl-6">
<Markdown markdown={message.text} partial={message.partial} />
<Markdown markdown={message.text} partial={message.partial} messageTs={message.ts} />
{message.images && message.images.length > 0 && (
<div style={{ marginTop: "10px" }}>
{message.images.map((image, index) => (
Expand Down Expand Up @@ -1170,7 +1170,7 @@ export const ChatRowContent = ({
{title}
</div>
<div className="border-l border-green-600/30 ml-2 pl-4 pb-1">
<Markdown markdown={message.text} />
<Markdown markdown={message.text} messageTs={message.ts} />
</div>
</>
)
Expand Down Expand Up @@ -1324,7 +1324,7 @@ export const ChatRowContent = ({
</div>
)}
<div style={{ paddingTop: 10 }}>
<Markdown markdown={message.text} partial={message.partial} />
<Markdown markdown={message.text} partial={message.partial} messageTs={message.ts} />
</div>
</>
)
Expand Down Expand Up @@ -1410,7 +1410,11 @@ export const ChatRowContent = ({
{title}
</div>
<div style={{ color: "var(--vscode-charts-green)", paddingTop: 10 }}>
<Markdown markdown={message.text} partial={message.partial} />
<Markdown
markdown={message.text}
partial={message.partial}
messageTs={message.ts}
/>
</div>
</div>
)
Expand All @@ -1429,6 +1433,7 @@ export const ChatRowContent = ({
<div className="flex flex-col gap-2 ml-6">
<Markdown
markdown={message.partial === true ? message?.text : followUpData?.question}
messageTs={message.ts}
/>
<FollowUpSuggest
suggestions={followUpData?.suggest}
Expand Down
36 changes: 35 additions & 1 deletion webview-ui/src/components/chat/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,31 @@ import { VSCodeButton } from "@vscode/webview-ui-toolkit/react"

import { useCopyToClipboard } from "@src/utils/clipboard"
import { StandardTooltip } from "@src/components/ui"
import { vscode } from "@src/utils/vscode"

import MarkdownBlock from "../common/MarkdownBlock"

export const Markdown = memo(({ markdown, partial }: { markdown?: string; partial?: boolean }) => {
interface MarkdownProps {
markdown?: string
partial?: boolean
messageTs?: number
onDeleteMessage?: () => void
}

export const Markdown = memo(({ markdown, partial, messageTs, onDeleteMessage }: MarkdownProps) => {
const [isHovering, setIsHovering] = useState(false)

// Shorter feedback duration for copy button flash.
const { copyWithFeedback } = useCopyToClipboard(200)

const handleDelete = () => {
if (onDeleteMessage) {
onDeleteMessage()
} else if (messageTs) {
vscode.postMessage({ type: "deleteMessage", value: messageTs })
}
}

if (!markdown || markdown.length === 0) {
return null
}
Expand All @@ -33,6 +49,8 @@ export const Markdown = memo(({ markdown, partial }: { markdown?: string; partia
opacity: 0,
animation: "fadeIn 0.2s ease-in-out forwards",
borderRadius: "4px",
display: "flex",
gap: "4px",
}}>
<style>{`@keyframes fadeIn { from { opacity: 0; } to { opacity: 1.0; } }`}</style>
<StandardTooltip content="Copy as markdown">
Expand Down Expand Up @@ -60,6 +78,22 @@ export const Markdown = memo(({ markdown, partial }: { markdown?: string; partia
<span className="codicon codicon-copy" />
</VSCodeButton>
</StandardTooltip>
{(messageTs || onDeleteMessage) && (
<StandardTooltip content="Delete message">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, the tooltip text “Delete message” is hardcoded. Use the i18n translation function for this user-facing string to support localization.

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

<VSCodeButton
className="delete-button"
appearance="icon"
style={{
height: "24px",
border: "none",
background: "var(--vscode-editor-background)",
transition: "background 0.2s ease-in-out",
}}
onClick={handleDelete}>
<span className="codicon codicon-trash" />
</VSCodeButton>
</StandardTooltip>
)}
</div>
)}
</div>
Expand Down