fix: setSelection not using MultipleNodeSelection
#2125
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
This PR rewrites
setSelectionto useMultipleNodeSelectionwhen spanning multiple blocks. When the start and end blocks are the same, the entire block content is selected, i.e.:TextSelectionspanning it is used.CellSelectionspanning all cells is used.NodeSelectionspanning theblockContentnode is used.Rationale
Currently,
setSelectionuses aTextSelectionwhen spanning multiple nodes. This can cause issues when the start/end blocks do not have content, as it's not possible to find aTextSelectionthat spans them.Changes
setSelectiongetSelectionfromJSONtoMultipleNodeSelectionmoveBlocksto work with aMultipleNodeSelection."Mod-a"keyboard handler which callssetSelectionon the whole document. The default"Mod-a"shortcut attempts to create aTextSelection, which has the aforementioned issues.Impact
Should not be a breaking change as the BlockNote API is unchanged.
Testing
We already have tests for
getSelection/setSelection. When implementing the changes, I ran them against the tests to ensure they were correct.Screenshots/Video
N/A
Checklist
Additional Notes