Skip to content

fix(diffs): keep the caret line highlighted during selection#858

Merged
necolas merged 3 commits into
beta-1.3from
debug-cursor-line-highlight
Jun 22, 2026
Merged

fix(diffs): keep the caret line highlighted during selection#858
necolas merged 3 commits into
beta-1.3from
debug-cursor-line-highlight

Conversation

@necolas

@necolas necolas commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Repro:

  1. Place a cursor on a line; the whole line is highlighted.
  2. Select across multiple lines.
  3. The line the cursor is on is no longer highlighted.

#updateSelections only applied the active-line highlight for a collapsed cursor. A ranged selection set a data-active attribute on the gutter line number instead, but that attribute has no CSS rule and is read nowhere, so the line lost its highlight as soon as the selection gained any width.

Highlight the line holding the caret (the selection head) for both collapsed and ranged selections, and remove the dead data-active path. getCaretPosition resolves the selection head, so backward selections highlight the start line. This also removes a per-update querySelectorAll, and the gutter number now highlights through data-selected-line.

Cover the collapsed and multi-line cases with a regression test.

Repro:
1. Place a cursor on a line; the whole line is highlighted.
2. Select across multiple lines.
3. The line the cursor is on is no longer highlighted.

#updateSelections only applied the active-line highlight for a
collapsed cursor. A ranged selection set a data-active attribute
on the gutter line number instead, but that attribute has no CSS
rule and is read nowhere, so the line lost its highlight as soon
as the selection gained any width.

Highlight the line holding the caret (the selection head) for
both collapsed and ranged selections, and remove the dead
data-active path. getCaretPosition resolves the selection head,
so backward selections highlight the start line. This also
removes a per-update querySelectorAll, and the gutter number now
highlights through data-selected-line.

Cover the collapsed and multi-line cases with a regression test.
@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffs Ready Ready Preview Jun 19, 2026 8:43pm
pierre-docs-diffshub Ready Ready Preview Jun 19, 2026 8:43pm
pierre-docs-trees Ready Ready Preview Jun 19, 2026 8:43pm
pierrejs-diff-demo Ready Ready Preview Jun 19, 2026 8:43pm

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eaba52a2fa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/diffs/src/editor/editor.ts

@fat fat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to me 💃

The editor renders its active-line highlight by calling the
component setSelectedLines, which commits a line-selection range
and fires the host onLineSelected callback. A caret or text
selection in the editor is not a gutter line selection, so an
editable File/FileDiff with a line-selection handler received a
bogus notification on every selection update.

Pass notify: false from the editor so the highlight renders
without committing a line selection, and widen the component
setSelectedLines type to accept the option.

Add a regression test asserting onLineSelected stays silent for a
multi-line editor selection.
@necolas

necolas commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@codex

@necolas necolas merged commit 25ba17a into beta-1.3 Jun 22, 2026
8 checks passed
@necolas necolas deleted the debug-cursor-line-highlight branch June 22, 2026 17:38
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.

2 participants