Skip to content

feat(editor): Add rounded selection#757

Open
ije wants to merge 5 commits into
beta-1.3from
editor/rounded-selection
Open

feat(editor): Add rounded selection#757
ije wants to merge 5 commits into
beta-1.3from
editor/rounded-selection

Conversation

@ije
Copy link
Copy Markdown
Collaborator

@ije ije commented Jun 1, 2026

Screenshot 2026-06-01 at 08 54 36

image

Can be disabled by adding:

import { Editor } from "@pierre/diffs/editor"
const editor = new Editor({ roundedSelection: false })

Copilot AI review requested due to automatic review settings June 1, 2026 01:05
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 1, 2026

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

Project Deployment Actions Updated (UTC)
pierre-docs-diffshub Ready Ready Preview Jun 1, 2026 1:05am
pierre-docs-trees Ready Ready Preview Jun 1, 2026 1:05am
pierrejs-diff-demo Ready Ready Preview Jun 1, 2026 1:05am
pierrejs-docs Ready Ready Preview Jun 1, 2026 1:05am

Request Review

Copy link
Copy Markdown

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

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: 292fc8c32b

ℹ️ 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 on lines +1570 to +1571
if (wrapStartChar === wrapEndChar) {
segmentWidth = this.#metrics.ch;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Skip zero-width wrapped selection slices

In wrap mode, any segment where wrapStartChar === wrapEndChar now gets a 1ch highlight. This happens for a multi-line selection ending at column 0 of a wrapped line, and also at soft-wrap boundaries where the selection only touches the next visual segment; the old code skipped those duplicate zero-width slices or rendered 0 width at the true line end. As a result the editor shows an extra highlighted cell on lines/segments that are not actually selected.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds configurable rounded selection rendering to the diffs editor, updating selection range rendering and CSS while also reorganizing nearby editor-related types.

Changes:

  • Adds roundedSelection to EditorOptions.
  • Reworks selection range rendering to support rounded-corner overlays.
  • Adds CSS selectors for rounded selection corners and renames component option types.

Reviewed changes

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

File Description
packages/diffs/src/types.ts Renames/reorders editor and component-related exported interfaces.
packages/diffs/src/editor/editor.ts Adds rounded-selection option and rewrites selection rendering/caching logic.
packages/diffs/src/editor/css.ts Adds CSS rules for rounded selection corner rendering.
Comments suppressed due to low confidence (1)

packages/diffs/src/types.ts:896

  • Renaming the exported DiffsEditorOptions type without leaving an alias is a public API break: types.ts is re-exported from src/index.ts, and there are no remaining DiffsEditorOptions exports. Existing consumers importing this type will fail to compile even though this PR is about selection rendering.
export interface DiffsComponentOptions extends BaseCodeOptions {
  enableGutterUtility?: boolean;
  enableLineSelection?: boolean;
  expandUnchanged?: boolean;
  lineHoverHighlight?: 'disabled' | 'both' | 'number' | 'line';
}

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

Comment on lines +1570 to +1571
if (wrapStartChar === wrapEndChar) {
segmentWidth = this.#metrics.ch;
Comment on lines +1582 to 1584
if (!isLastLine) {
segmentWidth += this.#metrics.ch;
}
Comment on lines +1635 to +1636
const top = this.#getLineY(line) + wrapLine * lineHeight;
const css = `width:${ch}px;transform:translateX(${left}px) translateY(${top}px);`;
Comment on lines +1681 to +1693
if (
previousSelectionRange === undefined ||
previousSelectionRange.line !== line ||
previousSelectionRange.wrapLine !== wrapLine
) {
renderCtx.previousSelectionRange = {
element,
line,
wrapLine,
left,
width,
};
}
height: 100%;
background-color: var(--diffs-bg);
}
[data-rtl] {
Comment on lines 1597 to 1601
// Render one selection range div for a single visual line. `applyEolSpacing`
// controls whether the trailing one-character "line continuation" marker is
// appended at the end. For wrapped logical lines this must be false on every
// visual segment except the last one, since an intra-line wrap is not a real
// newline and shouldn't visually extend past the wrapped content.
Comment on lines +1694 to +1701
if (
previousSelectionRange === undefined ||
end <= previousSelectionRange.left
) {
['rtl', 'rtr', 'rbl', 'rbr'].forEach((key) => {
dataset[key] = '';
});
} else {
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