Repository navigation
[lexical-selection] Bug Fix: Make $getSelectionStyleValueForProperty direction-independent - #8261
Merged
etrepum merged 2 commits intoMar 28, 2026
Conversation
…return consistent values regardless of selection direction (meta#8013) Replace null sentinel with boolean flag to avoid conflating "no nodes seen yet" with a valid default value, ensuring forward and backward selections return the same result.
Sathvik-Chowdary-Veerapaneni
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon,
takuyakanbr and
zurfyx
as code owners
March 26, 2026 04:35
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Mar 26, 2026
Skip start node when cursor is at end of it, skip end node when cursor is at beginning — handles both selection directions correctly.
Contributor
Author
|
reworked — now skips start node when cursor is at the end of it, and end node when cursor is at the beginning, so both boundaries are handled regardless of direction |
etrepum
approved these changes
Mar 28, 2026
Merged
This branch was successfully deployed
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.
Bug
Fixes #8013
$getSelectionStyleValueForPropertyreturns different values depending on whether the selection is forward or backward when text nodes have mixed styles.Root Cause
The function used
nullas a sentinel value to mean "no text node has been visited yet." Butnullcan also be a legitimatedefaultValuepassed by the caller, which causes the sentinel check (styleValue === null) to conflate "first iteration" with "unstyled node returned the default." This makes the function direction-dependent: iterating from an unstyled node to a styled node (forward) incorrectly returns the styled node's value, while iterating from styled to unstyled (backward) correctly returns''.Fix
Replace the
nullsentinel with a booleanisFirstflag. This cleanly separates the "first text node" check from the style value comparison, ensuring consistent results regardless of selection direction.styleValueis initialized todefaultValueinstead ofnullisFirstboolean tracks whether we've seen the first text nodestyleValuealready holdsdefaultValuewhen no text nodes are foundTest Plan
$getSelectionStyleValueForPropertyreturns the same value ('') for both