Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
This PR needs tests to demonstrate that it solves the issue
I have added the unit test to check this functionality |
etrepum
left a comment
There was a problem hiding this comment.
I don't think this is quite a complete solution, it's a bit greedy in that it will always clear formatting from the parent even if you've only selected some of the text. I think the block formatting should only be cleared if the block is selected, or all of its contents are selected.
etrepum
left a comment
There was a problem hiding this comment.
I don't think this is working correctly because if I create an empty ParagraphNode, set some formatting (e.g. center alignment) and then clear formatting then it stays center aligned
| if (!$isRangeSelection(postExtractSelection)) { | ||
| return; | ||
| } | ||
|
|
||
| const postExtractCaretRange = | ||
| $caretRangeFromSelection(postExtractSelection); | ||
| const anchorNext = $getCaretInDirection( | ||
| postExtractCaretRange.anchor, | ||
| 'next', | ||
| ); | ||
| const focusNext = $getCaretInDirection( | ||
| postExtractCaretRange.focus, | ||
| 'next', | ||
| ); | ||
|
|
||
| if ($comparePointCaretNext(anchorNext, focusNext) === 0) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
I'm not quite sure this is the correct logic but it looks like you were just trying to check if the selection was collapsed
| if (!$isRangeSelection(postExtractSelection)) { | |
| return; | |
| } | |
| const postExtractCaretRange = | |
| $caretRangeFromSelection(postExtractSelection); | |
| const anchorNext = $getCaretInDirection( | |
| postExtractCaretRange.anchor, | |
| 'next', | |
| ); | |
| const focusNext = $getCaretInDirection( | |
| postExtractCaretRange.focus, | |
| 'next', | |
| ); | |
| if ($comparePointCaretNext(anchorNext, focusNext) === 0) { | |
| return; | |
| } | |
| if (!$isRangeSelection(postExtractSelection) || postExtractSelection.isCollapsed()) { | |
| return; | |
| } |
|
Closing due to inactivity, re-open or create a new PR when/if you intend to continue working on this |
Description
Updated clear-formatting to detect the “no formatting” case by checking selection.extract() instead of comparing anchor/focus. This ensures alignment is cleared even when the selection is collapsed and no text formatting is present.
Closes #7383
lexical-format.mp4
Test plan
All the existing unit tests passed . No new tests created.