Repository navigation
Let a chat answer and each code block in it be copied, also where the page has no Clipboard API - #954
Merged
Conversation
… page has no Clipboard API Signed-off-by: dada-yan <BinjunYann@gmail.com>
WaylandYang
approved these changes
Sep 26, 2026
WaylandYang
left a comment
Contributor
There was a problem hiding this comment.
Item (3) of #936: the shell's IconButton on the answer and on each code block, copying the stored Markdown and the pre's text, and a fallback where the Clipboard API is missing over plain http, which is how most self-hosted bases are opened. The follow-up for the existing copy actions is noted. Merging.
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.
Does item (3) of #936. #936 stays open for (2), retry.
Problem
A chat answer cannot be checked, retried or copied #936 (3). An answer has no copy action, and neither does a code block inside it, although SQL and tables are what people most often copy.
The existing copy actions call
navigator.clipboarddirectly:The Clipboard API exists only in a secure context, meaning https or localhost. A base opened over plain http on a local network has no
navigator.clipboard. There these actions do nothing, and say nothing.Change
clipboard.ts:copyText(text)returns whether it copied.navigator.clipboardwhen the page has it.execCommand("copy"). Then it removes the area and returns focus to the element that had it.chatCopy.tsx:CopyButtonis the shell'sIconButtonwith theCopy/Checkicons. After a copy it shows the check and reads "Copied" for 1.5 s. A failed copy says so in a toast.CodeBlockwraps<pre>and puts aCopyButtonat its top right. It copies the code itself: the text of the<pre>, without the fence's final newline.chatCitations.tsx:chatMarkdownrendersprethroughCodeBlock. It is still a module-level constant, soSegment's memoization holds.Chat.tsx: a finished answer gains a row of actions under its sources, for now just "Copy answer".[n]marks, so tables and code paste as written.styles.css:<pre>gets right padding, so the button does not cover short lines.S.ask, inen.tsandzh.ts.Verification
Run in containers on a Linux host: Node 20 with pnpm 10.2.1, and Playwright 1.58.2 with Chromium.
New tests
clipboard.test.ts(vitest) covers four cases:execCommand("copy")runs, it is removed afterwards, and focus goes back;writeTextfalls back the same way;falsewhen neither works, whetherexecCommandreturnsfalseor throws.chat-view.test.mjs(browser) replays a stored answer with a SQL code block twice:navigator.clipboardreplaced by a recorder;execCommandrecording the selected text.Each time, "Copy code" copies exactly the SQL and the button then reads "Copied", "Copy answer" copies the whole Markdown, and the page logs no error.
On dev (f2e0d5b) with only the browser test added
The new case fails waiting for a "Copy code" button, which dev does not have: 22 tests, 20 pass, 2 fail (the case and its parent). The vitest file imports the new module, so it was left out.
With this change
pnpm install --frozen-lockfilepasses.pnpm test: 146 passed.pnpm buildpasses, including style-guard andtsc.Limits
navigator.clipboarddirectly. They can move tocopyTextin a follow-up.[n]marks. The sources listed under it are not copied.execCommand("copy")is deprecated. It is reached only where the Clipboard API is missing or refuses, and browsers still support it.