feat: expose insert text method - #613
Open
eszlamczyk wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new imperative insertText(text) API to EnrichedMarkdownTextInput so callers can insert markdown-parsed content at the current cursor/selection without reserializing and resetting the whole document. The implementation reuses the existing paste pipeline on both platforms and adjusts it to preserve leading/trailing newline runs verbatim (so block content can be inserted mid-paragraph without md4c “consuming” the outer newlines).
Changes:
- Exposed
insertTextas a native command and added it to the JS ref instance API. - Implemented
insertTexton iOS and Android via the existingpasteMarkdownflow; updatedpasteMarkdownto split/re-attach edge newlines. - Added Storybook coverage for the new method and disabled the Storybook story wrapper to fix text selection interactions.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-enriched-markdown/src/EnrichedMarkdownTextInputNativeComponent.ts | Adds insertText to codegen native commands. |
| packages/react-native-enriched-markdown/src/EnrichedMarkdownTextInput.tsx | Exposes insertText on the imperative ref instance. |
| packages/react-native-enriched-markdown/ios/input/EnrichedMarkdownTextInput.mm | Adds insertText: and updates pasteMarkdown: to preserve edge newlines. |
| packages/react-native-enriched-markdown/android/.../EnrichedMarkdownTextInputView.kt | Updates pasteMarkdown newline handling and adds insertTextAtCursor. |
| packages/react-native-enriched-markdown/android/.../EnrichedMarkdownTextInputManager.kt | Exposes insertText command to call into the view. |
| docs/API_REFERENCE.md | Documents the new insertText method. |
| apps/react-native-example/.rnstorybook/.../InsertText.stories.tsx | Adds a Storybook story demonstrating insertText. |
| apps/react-native-example/.rnstorybook/index.ts | Disables story wrapper to prevent selection collapse during touches. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
eszlamczyk
marked this pull request as ready for review
July 30, 2026 07:58
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.
What/Why?
Closes #286.
Adds an
insertText(text)imperative method toEnrichedMarkdownTextInputthat parses the given string as Markdown and inserts it literally at the current cursor position (replacing the selection if there is one). Previously the only way to insert text programmatically was thegetMarkdown+ splice +setValueworkaround, which reparses the whole document and loses line breaks.Implementation reuses the existing paste pipeline on both platforms (
pasteMarkdown), so inline formatting, block ranges, auto-link detection, undo and event emission all come from battle-tested code:insertTextcommand inEnrichedMarkdownTextInputNativeComponent.ts, exposed onEnrichedMarkdownTextInputInstance.insertText:delegates topasteMarkdown:(empty string is a no-op).insertTextAtCursor()wrapper overpasteMarkdown()plus theinsertTextmanager override.While testing, this surfaced a bug in
pasteMarkdownon both platforms: md4c consumes leading/trailing newlines as block structure, so inserting'\n- item\n'mid-word merged the list line with the surrounding text (te|stbecame a- tefirst itembullet). The newline runs are now split off before the parse and re-attached verbatim, making insertion fully literal — the caller controls separation. This also fixes clipboard paste of markdown that starts/ends with block content.Also fixes text selection inside storybook stories: the storybook story wrapper calls
Keyboard.dismiss()on every touch start, which collapsed selections and broke double-tap selection. Disabled viahasStoryWrapper: falsein.rnstorybook/index.ts.Testing
New
Methods/InsertTextstorybook story with three snippets (plain text, inline markdown, a newline-wrapped list). Manually verified on iOS simulator and Android emulator:lore<text>|m ipsum), cursor after the inserted text.'**bold**, *italic* and a [link](...)'renders formatted;getMarkdown()round-trips.'\n- first item\n- second item\n'atte|styieldste/ two bullets /ston separate lines.insertText('')with an active selection is a no-op.Screenshots
PR Checklist