refactor: simplify pr

This commit is contained in:
Catriel Müller
2026-02-20 12:53:09 -03:00
parent cb5e3cea23
commit 8dcc40f01b
3 changed files with 51 additions and 1 deletions
@@ -5,4 +5,8 @@
[data-slot="text-part-body"] {
margin-top: 0;
}
[data-slot="text-part-copy-wrapper"] {
display: none;
}
}
@@ -114,6 +114,24 @@
[data-component="text-part"] {
width: 100%;
[data-slot="text-part-body"] {
position: relative;
margin-top: 32px;
}
[data-slot="text-part-copy-wrapper"] {
position: absolute;
top: -28px;
right: 8px;
opacity: 0;
transition: opacity 0.15s ease;
z-index: 1;
}
[data-slot="text-part-body"]:hover [data-slot="text-part-copy-wrapper"] {
opacity: 1;
}
[data-component="markdown"] {
margin-top: 0;
font-size: var(--font-size-base);
+29 -1
View File
@@ -668,14 +668,42 @@ PART_MAPPING["tool"] = function ToolPartDisplay(props) {
PART_MAPPING["text"] = function TextPartDisplay(props) {
const data = useData()
const i18n = useI18n()
const part = props.part as TextPart
const displayText = () => relativizeProjectPaths((part.text ?? "").trim(), data.directory)
const throttledText = createThrottledValue(displayText)
const [copied, setCopied] = createSignal(false)
const handleCopy = async () => {
const content = displayText()
if (!content) return
await navigator.clipboard.writeText(content)
setCopied(true)
setTimeout(() => setCopied(false), 2000)
}
return (
<Show when={throttledText()}>
<div data-component="text-part">
<Markdown text={throttledText()} cacheKey={part.id} />
<div data-slot="text-part-body">
<Markdown text={throttledText()} cacheKey={part.id} />
<div data-slot="text-part-copy-wrapper">
<Tooltip
value={copied() ? i18n.t("ui.message.copied") : i18n.t("ui.message.copy")}
placement="top"
gutter={8}
>
<IconButton
icon={copied() ? "check" : "copy"}
size="small"
variant="secondary"
onMouseDown={(e) => e.preventDefault()}
onClick={handleCopy}
aria-label={copied() ? i18n.t("ui.message.copied") : i18n.t("ui.message.copy")}
/>
</Tooltip>
</div>
</div>
</div>
</Show>
)