Skip to content

Fat/selection#141

Merged
amadeus merged 25 commits into
mainfrom
fat/selection
Nov 13, 2025
Merged

Fat/selection#141
amadeus merged 25 commits into
mainfrom
fat/selection

Conversation

@fat

@fat fat commented Nov 8, 2025

Copy link
Copy Markdown
Contributor

This add a rich selection api to our diff and file components as well as implements a multi line comment ui in the comments and annotation example.

CleanShot.2025-11-07.at.17.30.39.mp4

@vercel

vercel Bot commented Nov 8, 2025

Copy link
Copy Markdown

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

Project Deployment Preview Updated (UTC)
pierrejs-diff-demo Ready Ready Preview Nov 13, 2025 11:35pm
pierrejs-docs Ready Ready Preview Nov 13, 2025 11:35pm

@@ -144,6 +168,7 @@ export function Annotations({ prerenderedDiff }: AnnotationsProps) {
backgroundColor: '#1a76d4',
transition: 'none',
cursor: 'pointer',
pointerEvents: 'none',

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 changed the logic here so that this is really like a "fake" button and clicking it really clicks through to the line number which is what ultimately triggers the comment adding.

Number of benefits here imo (particularly fixes annoying thing with mouse over / highlight state, etc.

@@ -155,6 +180,9 @@ export function Annotations({ prerenderedDiff }: AnnotationsProps) {
options={{
...prerenderedDiff.options,
onLineEnter: handleLineEnter,
enableLineSelection: !hasOpenCommentForm,

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.

@amadeus i think this is the right place for this stuff to live, but lmk if you'd rather it be top level

whiteSpace: 'normal',
margin: 20,
fontFamily: 'Geist',
marginLeft: -43,

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.

some tom foolery for this component, to make it simulate the continuation of the left gutter – like this:

Image

@@ -0,0 +1,454 @@
import type { AnnotationSide } from './types';

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 mostly tried to crib the logic from pierre.co for this guy – but follow existing code patterns. One thing to note is i ended up ripping out the url management… and just adding more event handers (assume people could wire that up + scroll to) themselves

lineAnnotations: lineAnnotations,
});
const instance = instanceRef.current;
const forceRender = !deepEqual(instance.options, options);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so the downside of this is that forceRender will become true when the selection updates, which will trickle down into the render step which is probably something we don't want.

We need to come up with a better way for these side-effecty things.

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.

yah that makes sense to me…

* First pass at improved handling for selection related code

* Unify composedPath generation

* Adding `data-alt-line` property to context lines

This will make it much easier to mux selection types between unified and
split diffs

* Reworked LineSelectionManager

This commit accomplished quite a lote

* Simplified and improved SelectedLineRange API
  * Much simpler interface with a more human API (similar in spirit to
    LineAnnotations)
* Selected lines fully transition between 'split' and 'unified' diffs
* DOM updates from mouse events are now debounced through
  requestAnimationFrame
* Rendering is now smarter to not actually perform dom node changes if
  not necessary
* Improved some O(n) when it comes to processing/updating lines

* Update docs to fit new types
* Tweak documentation for `selectedLines` in react components

* hopefully make it clearer

* More docs content updates

* consistency
@amadeus
amadeus merged commit 93ae5a2 into main Nov 13, 2025
7 checks passed
@amadeus
amadeus deleted the fat/selection branch November 13, 2025 23:40
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.

3 participants