Skip to content

Artifact viewer: highlight the word under the pointer to anchor the reader's eye #1802

Closed

Description

@amrmelsayed

Problem

When reviewing a document in the artifact viewer (the markdown preview backed by packages/artifact-canvas), there is no visual anchor that follows the pointer. Long prose paragraphs give the eye nothing to lock onto, so the reader loses their place as the pointer moves across a line and has to re-find it. Owner request (2026-10-13).

Expected

  • As the pointer moves over prose, the word under the pointer gets a soft rounded highlight (a muted pill behind the word, same tone family as the existing muted/hover colours, legible in both light and dark themes). It follows the pointer word by word with no lag the eye can notice and no flicker between adjacent words.
  • The highlight is purely visual. It does not change the DOM text, selection, copy, the review-marker anchoring (data-line), the injected comment cards, or the "+" add-comment affordance (artifact-canvas: full-row '+' affordance (GitHub-diff pattern) — structurally eliminate the hover travel-gap bug class #1343), all of which keep working exactly as today.
  • It clears when the pointer leaves the canvas body, when a drag-selection is in progress (left button held), and while the comment composer has focus. It does not render over injected comment cards, the composer, or the overlays (minimap, reading-mode toggle, keyboard help).
  • Works in both reading modes (vertical and horizontal columns) and at every preview font size / line height.
  • Switchable: a codev.markdownPreview.hoverWordHighlight setting (boolean). Default on.

Fix shape (hypothesis; verify in source)

The canvas body is imperatively owned (ArtifactCanvas.tsx, the bodyRef effect sets innerHTML and later injects comment cards), so the highlight must not wrap words in spans: a DOM rewrite would break data-line anchoring, marker verification and the card injection. Two DOM-free options, builder picks and states it in the plan:

  1. Overlay rects (recommended, matches the rounded look). On the existing onMouseMove path (activateFromPointer, throttled to one animation frame), resolve the caret at the pointer with document.caretRangeFromPoint(x, y) (or caretPositionFromPoint where available), expand the offset to word boundaries in the text node with Intl.Segmenter(undefined, { granularity: 'word' }) (fall back to a \p{L}\p{N} run), build a Range for the word, and paint one absolutely positioned, pointer-events: none element per getClientRects() fragment, positioned relative to the body wrapper. Dedupe on (text node, start, end) so a move within the same word does nothing. Clear on mouseleave, on buttons & 1, and on scroll (recompute from the last pointer position or clear).
  2. CSS Custom Highlight API. Register a Highlight holding the word Range and style it with ::highlight(codev-hover-word). Zero layout work, but ::highlight cannot draw rounded corners, so the look is a square tint. Acceptable only if the owner is fine with that at the dev gate.

Either way: one theme token (for example --codev-canvas-hover-word-background) with light and dark values in default-theme.css next to the existing tokens; the vscode host maps it like the other canvas colours. Skip the highlight inside pre/code (where a word is rarely the reading unit) unless the owner asks otherwise.

Plumbing: a new optional canvas prop (for example hoverWordHighlight?: boolean, default true) on the canvas props type, fed by the host from the setting the same way fontSizePx / lineHeight reach the preview (preview-provider.ts). Setting change re-posts to the open preview like the other preview settings.

Decisions for the owner

  • Default on (proposed) or off.
  • Apply inside code blocks or skip them (proposed: skip).
  • Headings and link text: included (proposed) or excluded.

Verification

Dev gate, real path: open a long plan in the preview, move the pointer across a paragraph, confirm the pill follows word by word with no flicker; check both themes and both reading modes; drag-select across lines and confirm no highlight renders and the selection is unaffected; hover a block that carries comment cards and confirm the "+" affordance, the cards and the composer behave as before; toggle the setting off and confirm it disappears without a reload.

Protocol

PIR (visual feel is tuned at the dev gate). Touches packages/artifact-canvas and apps/vscode/src/markdown-preview only; no contract surface. Owner: vscode architect.

Activity

  1. added
    area/vscode
    on Oct 12, 2026
  2. amrmelsayed commented on Oct 12, 2026

    @amrmelsayed
    CollaboratorAuthor

    On it! Working on this with the PIR protocol (plan + dev-approval gates before PR).

  3. added 14 commits that reference this issue on Oct 12, 2026
  4. amrmelsayed commented on Oct 16, 2026

    @amrmelsayed
    CollaboratorAuthor

    Shipped in PR #1812 (merged 0608145f1)

    Read this first if you are looking for what the title describes. The issue asks for the word under the pointer to be highlighted. That shipped, and it is one of six styles, but it is not the default. At the dev gate the owner reviewed a published lab of variants over a real spec and widened the ask, then moved the default to line-plus-paragraph, which draws no word pill. The title now understates the feature, deliberately.

    What shipped

    • Six highlight styles: none, word (the rounded pill from the mock), wordLine, wordLineParagraph, line, lineParagraph. The name lists the shapes drawn. Default: lineParagraph.
    • Three prose cursors: arrow (default, keeping artifact-canvas: show arrow cursor (not I-beam) over markdown content — content is read-only, comments are button-driven #1232's cursor: default), iBeam, hand.
    • One entry point: a "Reading Aids..." item in the preview's title-bar ... overflow menu, beside Reset Font Size, plus the settings codev.markdownPreview.hoverHighlight and codev.markdownPreview.readingCursor. No new on-page button: these are set-once preferences, unlike the per-document columns toggle.
    • Rendering: soft shapes in a separate fixed layer painted behind the glyphs (isolation: isolate with a z-index: -1 layer), so the canvas body's DOM is never written and data-line anchoring, comment cards and the composer are untouched. Flicker between words is handled by a sticky-on-gap rule, and nearest-caret false positives by a rect hit-test.
    • Exclusions: fenced code, comment cards, the composer and the "+" affordance are never lit and keep the arrow. Inline code keeps the band, the paragraph tint and the chosen cursor (it reads as part of the sentence); only the word pill is skipped there, because the chip's opaque background would hide it.
    • Themes: dark themes get stronger line and paragraph shading than light. That override lives in the VS Code host template keyed on the webview's theme-kind class, so the canvas package keeps its single foreground-derived palette.

    Decisions worth recording

    1. Default has no word pill (owner ruling at the dev gate, after two live feedback rounds). Not a regression.
    2. The line band spans the text on the word's line, not the block's full width (clipped to the column in columns mode). The approved plan said full block width; this deviation was accepted because it matches the reviewed lab and avoids a band running far past a short last line.
    3. Inline code is part of the sentence, superseding the plan's blanket "no highlight in code" for inline chips. Fenced code is still fully excluded.
    4. The published @cluesmith/codev-artifact-canvas prop defaults changed with this work (hoverHighlight defaults to lineParagraph), so any other host embedding the canvas inherits the new default on upgrade.

    Verification

    Three-way consultation: Gemini APPROVE, Codex COMMENT, Claude APPROVE, no REQUEST_CHANGES. Codex's two items were fixed before merge, one of them a real test hole: the scroll test previously passed when the highlight vanished entirely, and now requires a single shape that both moved and sits under the pointer. All seven required checks green on the merged head, including the real-browser Playwright job that covers the overlay behaviour.

    Changelog and release-notes entries are on docs/vscode-changelog (40cccb15a). Review and retrospective: codev/reviews/1802-artifact-viewer-highlight-the-.md.

    One unrelated finding, logged during this work and handed to the architect who owns packages/codev: two tests in cloud-config.test.ts build their "lax permissions" precondition with writeFileSync(..., { mode: 0o644 }), which the process umask masks. Under a restrictive umask one fails loudly and the other passes vacuously. Not touched here.

    Closing as complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/vscode

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions