fix(core): preserve text selection when toggling off list with AllSelection#7718
Open
togswr wants to merge 3 commits intoueberdosis:mainfrom
Open
fix(core): preserve text selection when toggling off list with AllSelection#7718togswr wants to merge 3 commits intoueberdosis:mainfrom
togswr wants to merge 3 commits intoueberdosis:mainfrom
Conversation
…election Verify that text selection is preserved (not collapsed) after toggling off a list when the entire document is selected via Ctrl+A. Covers: - single-item ordered list - single-item bullet list - multi-item ordered list
…ection `createInnerSelectionForWholeDocList()` (introduced in ueberdosis#7683) used structural boundary positions (from=1, to=list.nodeSize-1) to create a TextSelection. These positions sit outside inline content, so after `liftListItem` removes list/item wrappers, `TextSelection.map()` falls back to `Selection.near()` and collapses the selection. Replace `TextSelection.create()` with `TextSelection.between()`, which resolves non-text positions to the nearest valid cursor positions. This ensures the selection maps correctly through the lift operation and remains non-empty afterward. Regression from ueberdosis#7683 (fix for ueberdosis#7562).
🦋 Changeset detectedLatest commit: a74a05c The changes in this PR will be included in the next version bump. This PR includes changesets to release 72 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 |
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression in @tiptap/core list toggling where turning off a top-level list while the selection is an AllSelection (Ctrl/Cmd+A) caused the selection to collapse after lifting, which in turn makes UI like BubbleMenu disappear.
Changes:
- Update the internal “normalize AllSelection into the list” helper to use
TextSelection.between(...)so boundary positions resolve into valid inline positions and survive mapping throughliftListItem. - Add regression tests for ordered/bullet lists (single-item and multi-item) verifying selection preservation after toggling off with AllSelection.
- Add a changeset for a
@tiptap/corepatch release.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/core/src/commands/toggleList.ts |
Adjusts the AllSelection normalization selection creation to avoid collapsing after lift/mapping. |
packages/extension-list/__tests__/taskItem.spec.ts |
Adds regression coverage for selection preservation when toggling off lists with AllSelection. |
.changeset/fix-togglelist-allselection-selection.md |
Declares a patch changeset for the user-facing selection preservation fix. |
Add explicit assertions that selectAll() produces an AllSelection (from === 0, to === doc.content.size) before the toggle operation, matching the pattern used in existing tests.
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.
Changes Overview
Fix a regression introduced in #7683 where toggling off a list with AllSelection (Ctrl/Cmd+A) causes the text selection to collapse. After the list is lifted, the selection becomes empty (
from === to), causing the user to lose their selection and BubbleMenu to disappear.Implementation Approach
createInnerSelectionForWholeDocList()used structural boundary positions (from = 1,to = list.nodeSize - 1) to create aTextSelection. These positions sit outside inline content, so afterliftListItemremoves the list/item wrappers,TextSelection.map()falls back toSelection.near()and collapses the selection.Replace
TextSelection.create()withTextSelection.between(), which resolves non-text positions to the nearest valid cursor positions. This ensures the selection maps correctly through the lift operation and remains non-empty afterward.Position trace (single list item containing "abc"):
With
TextSelection.create:from=1 → 0,to=7 → 4— both at doc level, selection collapses.With
TextSelection.between:from=3 → 1,to=6 → 4— both inside paragraph, selection preserved.Testing Done
Added 3 regression tests verifying that text selection is preserved after toggling off a list with AllSelection:
Each test asserts exact
fromandtopositions after the toggle operation.Verification Steps
Checklist
Related Issues
Regression from #7683 (fix for #7562)