Feat/auto copy last code block element - #800
Conversation
|
I'll update it with the changeset |
|
Hey @akramcodez Please review this when you get the time. |
|
Hi @AryanNandanwar, thanks for taking this on and for the detailed PR description! I reviewed the code and noticed a major discrepancy between the plan you outlined in the issue thread and the actual implementation in this PR. 1. Architecture Flaw: Backend vs. Frontend Clipboard
2. Unrelated File Commits
3. Test Coverage
Once the clipboard logic is moved to |
|
Thanks for the feedback@akramcodez ! I'll update the PR accordingly |
048f98a to
0d2ee7d
Compare
|
Hey @akramcodez, changes have been updated. Here is a brief summary of what was addressed: Clipboardy Removal: Replaced clipboardy with direct DOM extraction and VS Code extension round-tripping. Targeted Code Selection: The webview queries .agent-markdown pre code (scoped strictly to assistant prose, skipping user echoes and thought boxes), takes the final block, and sends a typed copyToClipboard message to the host. Synchronized Rendering: Added flushPendingRender() to force any pending markdown renders before copying, ensuring mid-stream copies read the current DOM instead of the previous frame. Host Feedback: plugins/vscode/src/chat-webview-provider.ts responds with a copyResult message, which the webview converts into a "Copied N characters" toast. Unified Trigger Routing: /copy code typed in the chat input is intercepted locally in submitMessage() and invokes copyLastCodeBlock() without hitting the agent. /copy alone copies the entire last response as raw markdown. Ctrl+Alt+Shift+C handles copy events through two entry points: a webview keydown listener (when focused) and a VS Code keybinding on the nanocoder.copyLastCodeBlock command (scoped to focusedView == nanocoder.chatView). Cleanup: Removed unrelated file modifications (such as .devcontainer/devcontainer-lock.json and .gitignore). Please note that badges/forks.svg and badges/npm-downloads-monthly.svg were not added by me. PR Checklist: Left the "New features include passing tests in .spec.ts/tsx files" checkbox unchecked. |
|
Hey @AryanNandanwar - thanks for this, the design is right (webview finds the text, host owns the clipboard write) and the A few changes needed from my end before merge:
Minor, take or leave:
Thanks :) |
ff3c762 to
7e230b2
Compare
Co-authored-by: Cursor <cursoragent@cursor.com>
4893044 to
34223b3
Compare
|
Hey @will-lamerton , thanks for the thorough review! Addressed everything below: Required
Minor
Ready for another look when you have a moment. Thanks again! |
|
Thanks for this PR @AryanNandanwar - feel free to add yourself as a contributor to our website via a PR which I will approve :) https://nanocollective.org/contributors |
Description
Adds a keyboard-friendly way to copy AI output from the Nanocoder VS Code chat webview (closes #759).
In the sidebar chat you can:
/copyto copy the last full assistant response to the clipboard/copy codeto copy only the last fenced code block (<pre><code>in the messages DOM)Copy is scoped to assistant messages only (via an
agent-markdownmarker), so user echoes and thought boxes are ignored. The webview finds the text; the extension host writes it withvscode.env.clipboard.writeTextand shows a short in-webview toast.The chosen hotkey avoids conflicts with VS Code’s
Ctrl+Shift+C(external terminal) and Cursor’sCtrl+Alt+C(confetti). Terminal CLI/copybehavior is unchanged.Type of Change
Changeset
pnpm changeset) describing this change for the changelogDocs-only or internal chores need no changeset (or run
pnpm changeset --emptyto note that intentionally).Testing
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)(Webview UI lives under
plugins/vscode/, which is outside the root AVA/Biome suite; verified via TypeScript check, extension build, and manual testing below.)Manual Testing
Manual checks:
/copycopies the last full assistant response/copy codecopies the last fenced code block (indentation preserved, no extra trailing blank line)pnpm run build:vscode)Checklist