-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Labels
coreReconciler, DOM, Selection, Node, Events, CompositionReconciler, DOM, Selection, Node, Events, Compositionselection
Description
Lexical version: 0.38.2
Steps To Reproduce
- Have a plain TextNode followed by styled TextNode (using
$patchStyle({ color: "red" })for example) - Select both backwards and use
$getSelectionStyleValueForProperty(selection, "color"): the expected "" will be returned - Select both forwards and use
$getSelectionStyleValueForProperty(selection, "color"): the style in the second TextNode will be returned
The current behavior
if null is passed as the default value to
- Selection forwards from an unstyled TextNode to a styled TextNode returns the style from the styled TextNode
- Selection backwards from a styled TextNode to a precesing unstyled TextNode returns ""
The expected behavior
Selection of styled and unstyled TextNodes return "" no matter selection when null is the default
Root cause
In $getSelectionStyleValueForProperty this block returns different values depending on node order when the default value is null.
if (styleValue === null) {
styleValue = nodeStyleValue;
} else if (styleValue !== nodeStyleValue) {
// multiple text nodes are in the selection and they don't all
// have the same style.
styleValue = '';
break;
}- In the forwards iteration, from unstyled -> styled,
styleValueremainsnulland therefore the style overwrites thenulldefault and is returned rather than "". - In the backwards iteration, from styled -> unstyled, the unstyled node's
nodeStyleValue ofnullwill not match the precedingstyledValue` from the styled node and return "" correctly.
Metadata
Metadata
Assignees
Labels
coreReconciler, DOM, Selection, Node, Events, CompositionReconciler, DOM, Selection, Node, Events, Compositionselection