fix: unwanted space insertion in single line markdown text input when replacing selected text #718
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.
Fixes #716
Details
This PR fixes a bug where
MarkdownTextInputwithmultiline={false}incorrectly inserts spaces when users select all text and type a replacement character. The issue was caused by the library treating all text input as potentially multiline during processing, regardless of themultilineprop value.Root Cause:
The library was adding BR elements (containing
\ncharacters) and newlines during both DOM generation and text extraction phases, even for single-line inputs. These newlines then got converted to spaces during text normalization.Changes Made:
1. Fixed BR element addition in
addTextToElement()function (parserUtils.ts)isMultilineparameter2. Updated
addTextToElement()function calls (parserUtils.ts)isMultilineparameter to all function calls withinparseRangesToHTMLNodes()3. Enhanced
parseInnerHTMLToText()function (inputUtils.ts)isMultiline = trueparameter to maintain backward compatibility4. Connected multiline prop in
MarkdownTextInput.web.tsxmultilineprop toparseInnerHTMLToText()functionImpact:
Related Issues
GH_LINK
Manual Tests
Test Scenarios Covered:
Single-line text replacement:
MarkdownTextInputwithmultiline={false}Multiline preservation:
MarkdownTextInputwithmultiline={true}Markdown highlighting:
Edge cases:
Regression testing:
Manual Testing Steps:
multiline={false}andtype="markdown"