fix(web): setLink consistency - #774
Open
hejsztynx wants to merge 7 commits into
Open
Conversation
hejsztynx
commented
Aug 14, 2026
Comment on lines
+336
to
+350
| <button | ||
| className="btn btn-full" | ||
| onClick={() => { | ||
| if (!selection) return; | ||
| ref.current?.setLink( | ||
| selection.start, | ||
| selection.end, | ||
| '', | ||
| 'swmansion.com' | ||
| ); | ||
| }} | ||
| > | ||
| setLink(text="") | ||
| </button> | ||
|
|
Collaborator
Author
There was a problem hiding this comment.
This is for manual test purposes only. Will be removed on merge
hejsztynx
marked this pull request as draft
August 14, 2026 09:55
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes setLink behavior on web to match the native text-coordinate model and mobile semantics, ensuring link text serialization is consistent with onChangeSelection and allowing setLink(text="") to remove the selected range.
Changes:
- Use
nativeLeafText(...)for link text serialization inonLinkDetectedandsetLinkcomparisons to ensure consistent newline/leaf handling. - Update
setLinkon web to delete the selected range whentext === ""(instead of being a no-op). - Add Playwright e2e coverage for cross-paragraph selection round-tripping and add example-web UI hooks to exercise the behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/web/useOnLinkDetected.ts | Aligns emitted link text with native leaf-text serialization. |
| src/web/formats/EnrichedLink.ts | Fixes setLink semantics (delete on empty text) and uses native leaf-text for equality checks. |
| apps/example-web/src/testScreens/TestLinks.tsx | Captures and exposes onChangeSelection payload; adds a button to apply setLink from the captured selection. |
| apps/example-web/src/App.tsx | Adds a temporary manual-test button to call setLink with text="". |
| .playwright/tests/links.spec.ts | Adds e2e tests validating selection text round-trips through setLink across block boundaries (including inline marks). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
hejsztynx
marked this pull request as ready for review
August 14, 2026 10:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #757
There were two issues with
setLinkon web:onChangeSelectionreturnedtext="", the method was no-op, whereas on mobile it removes the text (what we want)Fix addresses both issues.
Added e2e tests for the first serialization related issue.
Added a temporary button in
example-webapp, so you can see what happens when you callsetLinkwithtext="". This will be reverted before the PR's merge.Test Plan
Experiment with
setLinkacross paragraph bounds and thesetLink(text="")button.Screenshots / Videos
Before:
The serialization differed, so
setLinkfalsely assumed thattextit got as an argument, differs from the actual text in the editor. This caused a path, where the content would get forcifully replaced with that "falsely new"text, which caused paragraphs to drop, and a literal\nto get inserted. It visually looks fine, but HTML proves the incorrectness.Screen.Recording.2026-08-14.at.12.18.10.mov
After:
Screen.Recording.2026-08-14.at.12.19.42.mov
Compatibility
Checklist