fix: scope editor.dom.getSelectionRect to the editor#2884
Merged
Conversation
🦋 Changeset detectedLatest commit: 3b67f9e The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📦 Bundle Stats —
|
| Metric | Value | vs main (d45a254) |
|---|---|---|
| Internal (raw) | 792.8 KB | +117 B, +0.0% |
| Internal (gzip) | 151.5 KB | +24 B, +0.0% |
| Bundled (raw) | 1.40 MB | +117 B, +0.0% |
| Bundled (gzip) | 315.6 KB | +23 B, +0.0% |
| Import time | 96ms | +1ms, +1.2% |
@portabletext/editor/behaviors
| Metric | Value | vs main (d45a254) |
|---|---|---|
| Internal (raw) | 467 B | - |
| Internal (gzip) | 207 B | - |
| Bundled (raw) | 424 B | - |
| Bundled (gzip) | 171 B | - |
| Import time | 2ms | +0ms, +1.2% |
@portabletext/editor/plugins
| Metric | Value | vs main (d45a254) |
|---|---|---|
| Internal (raw) | 2.7 KB | - |
| Internal (gzip) | 894 B | - |
| Bundled (raw) | 2.5 KB | - |
| Bundled (gzip) | 827 B | - |
| Import time | 7ms | -0ms, -2.1% |
@portabletext/editor/selectors
| Metric | Value | vs main (d45a254) |
|---|---|---|
| Internal (raw) | 79.7 KB | - |
| Internal (gzip) | 14.6 KB | - |
| Bundled (raw) | 75.2 KB | - |
| Bundled (gzip) | 13.5 KB | - |
| Import time | 8ms | +0ms, +2.0% |
@portabletext/editor/traversal
| Metric | Value | vs main (d45a254) |
|---|---|---|
| Internal (raw) | 26.2 KB | - |
| Internal (gzip) | 5.2 KB | - |
| Bundled (raw) | 26.1 KB | - |
| Bundled (gzip) | 5.1 KB | - |
| Import time | 6ms | +0ms, +1.5% |
@portabletext/editor/utils
| Metric | Value | vs main (d45a254) |
|---|---|---|
| Internal (raw) | 29.7 KB | - |
| Internal (gzip) | 6.2 KB | - |
| Bundled (raw) | 27.3 KB | - |
| Bundled (gzip) | 5.8 KB | - |
| Import time | 6ms | -0ms, -1.0% |
🗺️ . · ./behaviors · ./plugins · ./selectors · ./traversal · ./utils · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
📦 Bundle Stats — @portabletext/markdown
Compared against main (d45a254e)
| Metric | Value | vs main (d45a254) |
|---|---|---|
| Internal (raw) | 53.0 KB | - |
| Internal (gzip) | 9.6 KB | - |
| Bundled (raw) | 348.2 KB | - |
| Bundled (gzip) | 96.1 KB | - |
| Import time | 39ms | -1ms, -2.0% |
🗺️ View treemap · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
1796d0b to
1eb1151
Compare
1eb1151 to
4095f6b
Compare
getCaretRect to editor.domeditor.dom.getSelectionRect to any range
4095f6b to
4a62478
Compare
editor.dom.getSelectionRect to any rangeeditor.dom.getSelectionRect to the editor
4a62478 to
ca80a0b
Compare
ca80a0b to
91c9ba7
Compare
`getSelectionRect(snapshot)` returned the rect of the live document selection via `window.getSelection().getRangeAt(0)`, which is document-global: with focus outside the editor, or multiple editors mounted, it handed back a rect for an unrelated element, and the `snapshot` parameter was only null-checked, never used. It now maps the snapshot's selection through the model (`resolveSelection` + `rangeToDOMRect`, the same model-to-pixels step the engine's `findCurrentLineRange` uses), scoping the rect to this editor's selection and making the parameter load-bearing. A caret rect is a snapshot with a collapsed selection; an arbitrary range is a snapshot carrying it, no new parameter, consistent with sibling `dom` methods (`getBlockNodes`/`getChildNodes`) that read the snapshot's selection. The one behavior it no longer reflects is a transient DOM-vs-model divergence (mid-IME composition); no caller relied on it.
91c9ba7 to
3b67f9e
Compare
Merged
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.
editor.dom.getSelectionRect(snapshot)returned a rect for the wrong element whenever the editor didn't own the document selection. It readwindow.getSelection().getRangeAt(0), which is document-global: with focus outside the editor, or a second Portable Text editor mounted on the page, the browser's active selection is somewhere else entirely andgetSelectionRecthanded back that element's rect. Thesnapshotargument was dead weight, only null-checked, then ignored in favour of the live DOM.It now maps the snapshot's own selection to a rect:
resolveSelectionresolves the keyed selection against the snapshot's value and schema, andDOMEditor.toDOMRange(...).getBoundingClientRect()reads its geometry. That scopes the result to this editor and makessnapshotload-bearing. The signature is unchanged, and the range whose rect you want is expressed the way the siblingdommethods already take theirs, through the snapshot's selection (getBlockNodes/getChildNodesreadsnapshot.context.selectiontoo). A caret rect is a snapshot with a collapsed selection.getSelectionRecthas no callers inside the editor, so the change is inert internally. The pinning is a browser test with two stacked blocks that asserts the lower block's caret rect sits below the upper one's, and that an absent or unresolvable selection returnsnull. The gherkin delete suite, which drives the sametoDOMRange-to-rect path throughfindCurrentLineRange, stays green.The one behaviour it stops reflecting is a transient divergence between the DOM selection and the model, mid-IME composition where the DOM leads. Nothing consumed that.