fix(text-editor): style selection stuck to paragraph on empty line #7706
+32
−22
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.
Proposed behaviour
This PR addresses an issue where users can not pre-select typography styles on an empty line. By introducing a "zero-width space" placeholder, we allow the editor to maintain state and focus for a new node before text input begins.
Changing the typography dropdown on an empty row now explicitly creates a
TextNodeorStyledSpanNodematching the selected style. To ensure the browser maintains cursor focus within this new node, the content is initialized with a zero-width space character (\u200B).This enables "type-over" styling, allowing users to set their desired typography before they start typing on a new line.
after.mp4
Current behaviour
Pressing
Entercreates an empty paragraph row without an underlyingTextNodeorStyledSpanNode. TheuseEffectmanaging the typography dropdown defaults to "Paragraph" for empty rows.If a user attempts to change the typography on an empty row, the editor reverts the selection to "Paragraph" because there is no node to apply the style to. Styling currently only triggers if the row already contains text.
before.mp4
Checklist
d.tsfile added or updated if requiredQA
Additional context
Testing instructions