feat: every container around the selection is focused#2813
Open
christianhg wants to merge 1 commit into
Open
Conversation
Changes the focused-container rule in get-selection-state so every container ancestor that fully contains the current selection reports focused, matching the cumulative shape selected has had since v7. Only the innermost container reported focused before; outer chrome (table around a focused cell, code block around a focused line) was silently lying.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: ecde866 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 |
Contributor
📦 Bundle Stats —
|
| Metric | Value | vs main (25ad79a) |
|---|---|---|
| Internal (raw) | 787.6 KB | +1.1 KB, +0.1% |
| Internal (gzip) | 150.2 KB | +69 B, +0.0% |
| Bundled (raw) | 1.39 MB | +1.1 KB, +0.1% |
| Bundled (gzip) | 312.2 KB | +70 B, +0.0% |
| Import time | 99ms | -1ms, -1.4% |
@portabletext/editor/behaviors
| Metric | Value | vs main (25ad79a) |
|---|---|---|
| Internal (raw) | 467 B | - |
| Internal (gzip) | 207 B | - |
| Bundled (raw) | 424 B | - |
| Bundled (gzip) | 171 B | - |
| Import time | 2ms | -0ms, -7.1% |
@portabletext/editor/plugins
| Metric | Value | vs main (25ad79a) |
|---|---|---|
| Internal (raw) | 2.7 KB | - |
| Internal (gzip) | 894 B | - |
| Bundled (raw) | 2.5 KB | - |
| Bundled (gzip) | 827 B | - |
| Import time | 7ms | -0ms, -0.8% |
@portabletext/editor/selectors
| Metric | Value | vs main (25ad79a) |
|---|---|---|
| Internal (raw) | 79.0 KB | - |
| Internal (gzip) | 14.5 KB | - |
| Bundled (raw) | 74.5 KB | - |
| Bundled (gzip) | 13.3 KB | - |
| Import time | 8ms | -0ms, -2.8% |
@portabletext/editor/traversal
| Metric | Value | vs main (25ad79a) |
|---|---|---|
| Internal (raw) | 25.1 KB | - |
| Internal (gzip) | 5.0 KB | - |
| Bundled (raw) | 25.0 KB | - |
| Bundled (gzip) | 4.9 KB | - |
| Import time | 6ms | +0ms, +1.7% |
@portabletext/editor/utils
| Metric | Value | vs main (25ad79a) |
|---|---|---|
| Internal (raw) | 29.3 KB | - |
| Internal (gzip) | 6.1 KB | - |
| Bundled (raw) | 26.8 KB | - |
| Bundled (gzip) | 5.8 KB | - |
| Import time | 6ms | +0ms, +2.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 (25ad79a7)
| Metric | Value | vs main (25ad79a) |
|---|---|---|
| Internal (raw) | 53.0 KB | - |
| Internal (gzip) | 9.6 KB | - |
| Bundled (raw) | 347.6 KB | - |
| Bundled (gzip) | 96.0 KB | - |
| Import time | 40ms | +0ms, +0.4% |
🗺️ 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.
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.
A container's
focusedprop in adefineContainerrender callback now reportstruefor every container ancestor that fully contains the current selection, matching the symmetryselectedhas had since v7.Previously the focused-container loop in
get-selection-statestopped at the first hit — only the innermost container reportedfocused: true. An outer container chrome (the table around a focused cell, the code block around a focused line) was silently saying it wasn't focused even though the caret was inside it. Consumers wiring container chrome to focused state either accepted the lie or rebuilt the ancestor walk themselves.The rule
A container reports
focused: truewhen the entire current selection is contained within it.For a collapsed caret, every container ancestor satisfies this — the caret is a point, every ancestor contains that point, every ancestor reports focused.
For an expanded selection, only containers whose subtree contains both endpoints satisfy this. Computed as the intersection of the anchor's and focus's container ancestors — a container holds both endpoints iff it is an ancestor of both.
Behaviour delta
false, line:truetrue, line:truefalse, paragraph:truetrueNo existing
truebecomesfalse. All deltas arefalse → truefor legitimate "the user is editing inside me" cases.Implementation
SelectionState.focusedContainerPath: string | undefinedbecomesfocusedContainerPaths: Set<string>, mirroringselectedContainerPaths.useIsFocusedContainerkeeps its signature and contract (subscribe to "is this container holding the focus"); the implementation swaps the scalar equality check for.has(serializedPath). The store-and-subscribe shape inselection-state-context.tsxis unchanged — same per-sliceuseSyncExternalStoremechanism, same re-render surface.The collapsed branch walks ancestors once. The expanded branch walks anchor ancestors and focus ancestors and intersects — no new traversal util needed.
Tests
src/editor/get-selection-state.test.ts— covers every case in the matrix above plus backward selection. Each test asserts the FULLfocusedContainerPathsset viatoEqual(new Set([...])), not spot checks.tests/container-render-focused-selected.test.tsx— updates the existing browser tests where they encoded the innermost-only rule. The expanded-across-cells test keeps its expectations: cells still reportfocused: falsebecause neither cell contains both endpoints.Targeted browser sweep: all container suites green (64/64).