[lexical-clipboard] Inherit style when typing after pasting rich text#7657
[lexical-clipboard] Inherit style when typing after pasting rich text#7657etrepum merged 5 commits intofacebook:mainfrom achaljhawar:paste-style-inheritance
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
etrepum
left a comment
There was a problem hiding this comment.
It probably makes sense to move this code into its own function (called by $insertGeneratedNodes) and write some tests for it.
The NodeCaret APIs could be used to iterate through the nodes in the 'previous' direction until a TextNode or block element is found
|
@etrepum how exactly should I use the the node caret api here? |
|
Probably something like this (untested): // usage: nodeToInspect = $getClosestTextNodeInBlock($caretFromPoint(selection.anchor, 'previous'));
function $getClosestTextNodeInBlock<D extends CaretDirection>(anchorCaret: PointCaret<D>): null | TextNode {
if ($isTextPointCaret(anchorCaret)) {
return anchorCaret.origin;
}
const range = $getCaretRange(anchorCaret, $getChildCaret($getRoot(), 'next').getFlipped());
for (const caret of range) {
if ($isTextNode(caret.origin)) {
return caret.origin;
} else if ($isBlockElementNode(caret.origin)) {
break;
}
}
return null;
} |
|
@etrepum I have implemented nodecaret apis update the logic as you said. |
etrepum
left a comment
There was a problem hiding this comment.
The code all looks good and I confirmed that it works as expected in the playground, the only thing missing here is a unit or e2e test to show that it works (and to prevent future regressions)
etrepum
left a comment
There was a problem hiding this comment.
Looks right other than the nested editor.update
…#7657) Co-authored-by: Bob Ippolito <bob@redivi.com>
Description
When pasting rich text content, the editor selection's active format and style are now updated to match the style of the last character of the pasted content.
This ensures that continuing to type after a paste operation will correctly inherit the formatting (e.g., bold, italics, background-color, font-size) from the pasted material.
Closes #7490
Test plan
Before
Lexical.Playground.5.mp4
/automated-tests*
After
Lexical.Playground.4.mp4