feat(vscode): add per-message Copy Markdown action on assistant replies#106
Merged
Merged
Conversation
Add a small clipboard action under every assistant message that posts
the raw Markdown source (including code fences and raw KaTeX) via the
existing copyToClipboard message, so users can paste the answer
elsewhere without losing formatting or math.
- Export getAssistantMarkdownSource(parts) and
getCopyableAssistantMarkdownSource(parts, { isUser, isShell }) from
MessageItem.tsx. The former joins visible TextPart.text values with
"\n\n" and returns null when there is nothing copyable; the latter
short-circuits to null for user messages and shell-result assistant
messages so only normal assistant replies qualify.
- Render a <button type="button"> with an inline double-pages SVG
clipboard icon when copyable Markdown source exists. The button is
hidden for user messages, shell user/assistant messages, and
messages whose non-text parts produce no copyable text. A 1.5s
checkmark-icon feedback mirrors the existing code-block copy UX.
aria-label and title stay as the localized "message.copyMarkdown"
string for screen readers; the visible content is the icon, not the
label.
- Add message.copyMarkdown to all 8 locales (en, ja, ko, zh-cn,
zh-tw, es, pt-br, ru). The value is used for aria-label and title;
the button body is the icon.
- Add a .copyMarkdownButton block to MessageItem.module.css with
hover (--vscode-foreground + --vscode-toolbar-hoverBackground),
:focus-visible outline (--vscode-focusBorder), and a .copied
modifier using --vscode-charts-green. The icon button does not
declare user-select, so its label text inside aria-label/title
remains native-selectable.
- Switch package.json activationEvents from [] to
["onView:opencode.chatView"] to make view-triggered activation
explicit instead of relying on implicit auto-activation.
- Add 24 new MessageItem.test.tsx cases covering: getAssistantMarkdownSource
and getCopyableAssistantMarkdownSource (10), render/hide
conditions for the Copy Markdown button (7), postMessage payload
shape including raw KaTeX and "\n\n"-joined multi-part sources
(6), code-block vs message-level copy independence (2), and
native copy/selection independence (5). Use vi.useFakeTimers to
assert the 1.5s copied-icon feedback reverts.
- Add 2 TextPartView.test.tsx cases asserting the code-block copy
button still posts only the <pre><code> text and excludes the
code fence and surrounding prose.
- No changes to TextPartView.tsx, vscode-api.ts, the extension host,
the clipboard transport type, KaTeX rendering, CSP, or the
code-block copy path.
Owner
|
@zeug-zz これレビューしちゃってもいいですか?良さそうだったらreviewerに入れてください! |
Author
3f7b0d8 to
e371598
Compare
ktmage
approved these changes
Jun 12, 2026
Comment on lines
+37
to
+39
| "activationEvents": [ | ||
| "onView:opencode.chatView" | ||
| ], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a per-message clipboard action under assistant messages that copies the raw Markdown source (including code fences and raw KaTeX) via the existing
copyToClipboardwebview message.What changes
getAssistantMarkdownSource(parts)andgetCopyableAssistantMarkdownSource(parts, { isUser, isShell })fromMessageItem.tsx.getAssistantMarkdownSourcejoins visibleTextPart.textvalues with\n\nand returnsnullwhen there is nothing copyable.getCopyableAssistantMarkdownSourceshort-circuits tonullfor user messages and shell-result assistant messages so only normal assistant replies qualify.<button type="button">with an inline double-pages SVG clipboard icon when copyable Markdown source exists. The button is hidden for user messages, shell user/assistant messages, and messages with no copyable text.copyToClipboardmessage path — no new extension-host clipboard APIs.Impact
pnpm checkintroduces no new warnings in the touched files