Skip to content

Blend the edit mode backgrounds#909

Merged
mdo merged 3 commits into
beta-1.3from
mdo/blend-edit-bg
Jul 1, 2026
Merged

Blend the edit mode backgrounds#909
mdo merged 3 commits into
beta-1.3from
mdo/blend-edit-bg

Conversation

@mdo

@mdo mdo commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

This adds some functionality to blend the selection color of edit mode with the diff line background.

@mdo mdo requested review from amadeus, Copilot, ije and necolas June 29, 2026 22:39
@vercel

vercel Bot commented Jun 29, 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 Jul 1, 2026 4:37am
pierre-docs-diffshub Ready Ready Preview Jul 1, 2026 4:37am
pierre-docs-trees Ready Ready Preview Jul 1, 2026 4:37am
pierrejs-diff-demo Ready Ready Preview Jul 1, 2026 4:37am

Request Review

Copilot AI 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.

Pull request overview

This PR improves edit-mode selection rendering by ensuring the selection overlay visually composites with the underlying diff line background, including better handling of rounded selection corners.

Changes:

  • Move diff line background painting to a [data-line]::after layer so the translucent selection overlay can blend over it.
  • Update the current-line highlight styling to avoid double-tinting by basing it on --diffs-computed-diff-line-bg.
  • Add an editor helper to read a line’s painted background color and pass it into selection-corner masking via a CSS variable.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/diffs/src/editor/editor.ts Reads the line’s painted background color and plumbs it into selection-corner rendering.
packages/diffs/src/editor/editor.css Refactors line background rendering to a ::after layer and updates selection-corner masking/background behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2865 to +2869
const cornerBg = this.#lineBackgroundColor(line);
const css =
`width:${ch}px;transform:translateX(${left}px) translateY(${top}px);` +
(cornerBg !== undefined
? `--diffs-selection-corner-bg:${cornerBg};`
Comment on lines 46 to 51
[data-line] {
cursor: text;
/* Transparent so the line's in-flow background can't hide the selection
overlay (z-index -10); the line color moves to the ::after layer below it. */
background-color: transparent;
}

@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: 576be40f99

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/diffs/src/editor/editor.ts
// Painted background color of a line, read from the [data-line]::after layer
// (the line element itself is transparent in edit mode). Returns undefined when
// that layer is transparent (e.g. context lines).
#lineBackgroundColor(line: number): string | undefined {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is it possible to use color-mix in editor.css instead of dynamically adding --diffs-selection-corner-bg?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, because the selection is on another layer, so it has no access to the line color. data-editor-overlay is where the selection range lives. That said, I do think we'll need to cache some of the values if we decide to go this route.

@necolas necolas 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.

lgtm once agents are appeased

Rounded selection corner masks capture the resolved line-background color
when the selection is drawn, so a theme swap (light/dark toggle or theme
name change) left them showing wrong-colored corners on diff-colored lines
until the selection moved. The tokenizer now fires an onThemeChange callback
from #emitThemeChange (covering the system observer, matchMedia, and
syncTheme paths, and the editor re-renders the selection overlay on the
next frame so the corners recompute against the new colors.
EOF
)

@ije ije left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@mdo mdo merged commit 5ef6f8a into beta-1.3 Jul 1, 2026
8 checks passed
@mdo mdo deleted the mdo/blend-edit-bg branch July 1, 2026 05:59
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.

4 participants