[lexical-markdown] Bug Fix: Fix incorrect format tag placement at link boundaries #8085
+17
−43
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.
Description
Current Behavior:
There is an issue where markdown format tags (e.g. bold, italic) are incorrectly placed when a format starts or ends at a link boundary. This happens because the formatter attempts to minimize the number of tags by looking across inline element siblings, leading to the following bugs:
Format starting inside a link: When a format is applied to text within a link, the formatter fails to close the tag inside the link because it expects the format to continue into the parent's next sibling. This results in the tag opening inside the link but closing outside of it (Refer to #7817).
Format ending inside a link: Since formatting is applied only to the text node within the link and not the link element itself, the closing tag is often omitted or misplaced (Refer to #7503).
Changes in this PR:
I have simplified the getTextSibling() function to ensure correct tag placement.
Previously, the logic attempted to traverse siblings of inline elements (like links) to minimize the total number of markdown tags. While this aimed for "cleaner" markdown, it resulted in syntactically incorrect tag at boundaries.
This PR prioritizes structural correctness over tag minimization. By ensuring tags are closed and opened correctly relative to the link boundaries:
Markdown integrity is preserved even if it requires slightly more tags.
I have verified this fix against the reported issue and existing tests. All relevant tests, including those involving links, have passed.
PR Closes #7503, Closes #7811 , Closes #7817
Test plan
Before
before.mov
After
after.mov