Skip to content

BUG: Cmd+A inside a code/markdown preview in chat selects the full session instead of scoping to the block #154

Description

@jeonghun-jj-lee

Summary

Cmd+A inside a rendered code block or markdown preview in the chat view selects the entire session rather than scoping to just that block's content. Expected behavior: Cmd+A within a code preview highlights only the code block text, allowing a quick Cmd+C to copy that snippet.

Context

  • Extension: harmoniqs.amicode-0.2.1
  • Engine: v1.18.10-amicode.4 (harmoniqs/opencode)
  • OS: Darwin 25.5.0 arm64
  • Surface: global-clipboard.ts (Cmd+A handler in the webview iframe)

The root cause is known: keydown events fire on the focused element (the scroll viewport with tabIndex=0), not the element the user clicked inside. So event.target.closest('[data-component="markdown-code"]') never matches — the target is always the viewport ancestor, not the code block descendant.

Expected vs actual

  • Expected: Cmd+A inside a code block selects only that block's content (scoped select-all).
  • Actual: Cmd+A selects the full chat session regardless of where the user clicked.

Enhancement note

A visible "Copy" button on code previews in agent-authored code edits (similar to the existing button on fenced code blocks in markdown messages) would also address the primary use case.

Diagnostics
  • Code blocks render as div[data-component="markdown-code"] > pre.shiki > code
  • The scroll viewport (div.scroll-view__viewport[tabIndex=0]) captures focus on click
  • Keyboard events dispatch to the focused viewport, not the clicked child
  • Possible fix directions: (a) make code blocks focusable (tabIndex=0 on the wrapper), (b) track last-clicked element via mousedown and use that for Cmd+A scoping, (c) rely on the existing per-block copy button

intake: not-ready — mature per the maturity contract before picking up
suggested_path: B
diagnostics: inline
upstream: none found

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions