Skip to content

fix(app): Cmd+C/Ctrl+C copies highlighted text in non-editable chat content (#136) - #152

Merged
jeonghun-jj-lee merged 2 commits into
local/amicodefrom
fix/136-clipboard-copy-non-editable
Aug 9, 2026
Merged

fix(app): Cmd+C/Ctrl+C copies highlighted text in non-editable chat content (#136)#152
jeonghun-jj-lee merged 2 commits into
local/amicodefrom
fix/136-clipboard-copy-non-editable

Conversation

@jeonghun-jj-lee

Copy link
Copy Markdown
Contributor

Summary

Cmd+C on selected text in the chat panel (rendered messages, code blocks) silently failed — the clipboard retained its previous content. Right-click → Copy worked because it explicitly calls writeClipboardViaBridge.

Root cause

global-clipboard.ts:186 bailed on non-editable targets:

if (!isEditableTarget(target)) return // non-editables keep native behavior

The assumption ("native behavior works") is false inside a VS Code webview iframe. Electron intercepts Cmd+C at the host level before a copy event fires in the iframe DOM.

Fix

Extend the existing capture-phase keydown handler to bridge Cmd+C/X/A for non-editable targets through writeClipboardViaBridge — the same path the context menu already uses.

Behavior

Shortcut Non-editable target Effect
Cmd+C Selection exists Copies selection to clipboard via bridge
Cmd+C No selection No-op (clipboard unchanged)
Cmd+X Selection exists Copies selection (no delete — read-only DOM)
Cmd+A Any selectAllChildren(document.body)
Cmd+V/Z/Y Any No-op (nothing to paste into or undo)

Structure

onKeyDown:
  [framing/modifier/key guards — unchanged]

  if NOT editable:
    C/X → bridge selection via writeClipboardViaBridge
    A   → selectAllChildren(document.body)
    return (V/Z/Y on non-editables: no-op)

  [existing editable logic — unchanged]

Constraints preserved

  • CLIPBOARD_SELF_SELECTOR opt-out unaffected (it is paste-only)
  • No second event listener introduced
  • writeClipboardViaBridge remains the sole outbound clipboard path
  • Extension-host side (chat_bridge.ts clipboard-write handler) needs no changes

Fixes #136

…ontent (#136)

Inside the VS Code webview iframe, Electron intercepts Cmd+C at the host
level before a `copy` event fires in the iframe DOM. The existing
capture-phase keydown handler bailed on non-editable targets — the
assumption that 'native behavior works' is false in this context.

Fix: extend the onKeyDown handler to bridge Cmd+C/X/A for non-editable
targets through `writeClipboardViaBridge`, the same path the context
menu's Copy already uses successfully.

- Cmd+C: reads window.getSelection(), writes via bridge
- Cmd+X on non-editable: copy-only (cannot delete from rendered DOM)
- Cmd+A on non-editable: selectAllChildren(document.body)
- No selection → no-op (clipboard unchanged)
- Existing editable-target behavior unchanged
- CLIPBOARD_SELF_SELECTOR opt-out unaffected (paste-only)

Fixes #136
The original fix bridged Cmd+C for highlighted text in non-editable chat
content, but the Cmd+A → Cmd+C sequence to copy the full session failed:
the prompt input held focus, so the non-editable path never fired, and the
virtualised timeline meant DOM selection was incomplete anyway.

Fix: serialize the full session from the message store (data model) rather
than relying on DOM selection.

- Add sessionCopyProvider slot (registered by the session page; returns
  the full session as markdown with role labels)
- Cmd+A on an empty prompt arms a fullSessionCopyPending flag and
  visually highlights the timeline (best-effort); Cmd+A on a non-empty
  prompt preserves standard select-all-in-editor behavior
- Cmd+C when the flag is armed calls the provider → writeClipboardViaBridge
- Non-editable Cmd+A → Cmd+C path also uses the provider when available
- Cmd+A inside #review-panel scopes to that panel's content
- Add serialize-session.ts (messages + parts → markdown text)
- Fix stale test from the prior commit (non-editable interception)
- 49 tests pass (41 clipboard + 8 serializer)

Known limitation: Cmd+A inside a rendered code block selects the full chat
rather than scoping to the block (keydown target is the focused viewport,
not the clicked element). Code blocks already have a copy button for this.
@jeonghun-jj-lee
jeonghun-jj-lee merged commit f2e8865 into local/amicode Aug 9, 2026
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Cmd+C / Ctrl+C does not copy highlighted text in the chat panel

1 participant