Repository navigation
[lexical-selection][lexical-utils] Bug Fix: Preserve selection coverage across mixed typography - #9196
Conversation
…ge across mixed typography
|
Hi @minwookshin! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
mayrang
left a comment
There was a problem hiding this comment.
This looks like the right direction — isContainedRect seems like the correct predicate here, and the new tests do a good job of capturing the bug.
The CLA check is failing — PRs can't be merged without a signed CLA. Please sign at https://code.facebook.com/cla.
One thing on the new browser test — see the inline comment.
| root.style.cssText = | ||
| 'position:absolute;left:20px;top:20px;width:600px;padding:0;font:16px/1.5 Arial'; | ||
| root.innerHTML = html; | ||
| document.body.append(root); |
There was a problem hiding this comment.
The existing dedupeSelectionRectsUnderpaint.test.ts adds void root.offsetHeight after setting innerHTML to flush layout before measuring. Probably better to follow the same pattern here.
```suggestion
root.innerHTML = html;
void root.offsetHeight;
```
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
etrepum
left a comment
There was a problem hiding this comment.
Codex found two regressions here:
Reviewed 21304dcd15cf1dc75edc206f94a40c7012f9ad23. I’d request changes for two confirmed regressions:
-
[P2] Retaining the smaller rectangle moves Yjs’s remote caret to the wrong endpoint. Select
Small beforeat 16px followed byLARGEat 40px. The larger run sorts first; the newly retained smaller run sorts last. Yjs’s default overlay path attaches the caret to the last rectangle (SyncCursors.ts:624–626), so the caret and name move to the end ofSmall before. In Chromium, the caret’s x-coordinate changes from approximately 240.75 on the parent to 106.11 on this PR, while the selection endpoint remains 240.73. Position the caret from the range endpoint independently of the highlight rectangles, and add a collaboration regression test. -
[P2] Strict containment upstream introduces additional underpainting downstream. In the existing
dedupeSelectionRectsUnderpaint.test.tsfixture, changevertical-align:0.5pxtovertical-align:-1px. The parent preserves the wide text highlight. This PR retains an additional narrow rectangle because its bottom extends 1px below the wide rectangle.positionNodeOnRangethen callsdedupeSelectionRects, whose 1px containment tolerance discards the wide rectangle and keeps the narrow one. My Chromium reproduction reduces approximately 154px of text highlight to 9.6px. Coordinate the two filters so newly retained partial overlaps cannot erase previously covered text, and test this downward-shifted variant.
Both originate in the changed containment predicate at packages/lexical-selection/src/utils.ts:164–169.
|
Updated selection rect handling to preserve coverage across mixed typography and positioned collaborator carets at the actual focus point. Unit, browser, type, and lint checks pass locally. |
etrepum
left a comment
There was a problem hiding this comment.
Codex noted one additional edge case:
[P2] Handle zero-size rectangles when positioning element-point carets — packages/lexical-yjs/src/SyncCursors.ts:498–508
A collapsed DOM range at an element boundary can return an all-zero rectangle. positionCaretAtFocus accepts that rectangle, places the caret at the origin, and returns true, preventing fallback positioning.
Confirmed in Chromium with collaboration v2:
- Paragraph containing
"ab cd". - Anchor:
(text, 0, text). - Focus:
(paragraph, 1, element). - Previous cursor implementation: caret at
(124, 138), correctly following the text. - This revision: caret at
(0, 0)with the fallback 16px height.
Resolve element points to a measurable text/DOM boundary, or fall back to valid selection geometry when the collapsed range has no usable bounds. Add a browser regression covering v2 element-point selections; the new tests only exercise text-point focus positions.
|
Handled zero-size DOM ranges at v2 element-point carets and flushed layout after mounting the selection fixture. Browser regressions (8), unit tests, typecheck, formatting, and lint pass locally. |
Description
Persistent selections can omit smaller text preceding a larger run on the same line, including while the Playground's link input has focus. A larger rectangle sorts before the smaller one, and the overlap check discards the latter even when it covers unique selected text.
Discard only fully contained rectangles in
createRectsFromDOMRange. Preserve the existing sort, full-width block exclusion and downstream Safari deduplication behavior. Add native Range regressions for mixed typography, partial overlap, wrapped LTR/RTL text and duplicate rectangles; update the utility characterization for the corrected containment contract.Closes #9184
Closes #9187
Test plan
Before
The new mixed-size regression fails against baseline implementation
83e8b49:Selection should cover "Small before " at (0.1, 0.1). The actual Playground leaves the first selected text run unpainted after focus leaves the editor.After
These screenshots were captured on
83e8b49. The three candidate files remained byte-identical after synchronization to the tested PR parent,bc4dcc814f66e35b00f8e3b8b235e559f07454f2.VITEST_BROWSER=chromium,firefox,webkit pnpm exec vitest run --project browser packages/lexical-selection/src/__tests__/browser --maxWorkers=1tsconfig.test.json. The separate benchmark repair is [lexical] Chore: Migrate benchmarks to the Vitest 5 API #9194; a macOS watcher-fixture repair is [lexical-compiler] Bug Fix: Normalize temporary paths in watcher tests #9195. With both maintenance fixes, the combined local checkout passes the full test TypeScript graph and 8,536 unit tests, with one existing skip. Those maintenance changes are excluded from this PR.The subsequent upstream commit
2fd17f0touches other files, and this patch applies cleanly to it. Local results above use the recorded parent. The full remote CI matrix, native mobile and screen-reader behavior remain unverified. This does not change the separate downstream keep-smaller policy for overlapping decorators.Source and visual evidence. AI-assisted implementation and validation with OpenAI Codex.