Repository navigation
feat: add removeInvalidMentionContent prop - #858
Open
JaydeepAgravat wants to merge 2 commits into
Open
JaydeepAgravat wants to merge 2 commits into
JaydeepAgravat wants to merge 2 commits into
Conversation
When true, changing the text of an inserted mention (typing inside it, deleting part of it, autocorrect) removes the whole mention instead of leaving plain text. Defaults to false, so the current behaviour is unchanged. Closes software-mansion#855
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Active issues include an Android crash when deleting across two mentions and incomplete mention-content removal on web and iOS, including during initial mount.
4 open issues
What changed in this PR
Adds the opt-in removeInvalidMentionContent prop to address #855, allowing edited mentions to be removed entirely rather than converted to plain text across iOS, Android, and web.
Changes:
- Exposes the prop through public types, native bindings, and web configuration, defaulting to
false. - Adds platform-specific deletion handling for invalid mentions.
- Documents the behavior and adds example toggles, web unit tests, and browser tests.
| File | Description |
|---|---|
src/web/pmPlugins/MentionPlugin/types.ts |
Adds the removal-mode option getter. |
src/web/pmPlugins/MentionPlugin/removeMentionMarksIfSpansResized.ts |
Adds deletion of resized mention ranges. |
src/web/pmPlugins/MentionPlugin/index.ts |
Passes the removal option into cleanup. |
src/web/EnrichedTextInput.tsx |
Connects the prop to the mention plugin. |
src/web/__tests__/removeMentionMarksIfSpansResized.test.ts |
Tests cleanup modes and edit boundaries. |
src/types.ts |
Defines and documents the public prop. |
src/spec/EnrichedTextInputNativeComponent.ts |
Adds the native component prop. |
src/native/EnrichedTextInput.tsx |
Forwards the prop to native implementations. |
ios/styles/MentionStyle.mm |
Deletes invalid mention content in removal mode. |
ios/EnrichedTextInputView.mm |
Applies the prop to iOS configuration. |
ios/config/EnrichedConfig.mm |
Stores, copies, and exposes the setting. |
ios/config/EnrichedConfig.h |
Declares configuration accessors. |
docs/docs/rich-text-formatting/mentions.mdx |
Explains mention-editing behavior. |
docs/docs/api-reference/enriched-text-input.md |
Documents the prop and platform support. |
apps/example/src/screens/DevScreen.tsx |
Adds a native example toggle. |
apps/example-web/src/testScreens/TestMentions.tsx |
Adds a web test-screen toggle. |
android/src/main/java/com/swmansion/enriched/textinput/styles/ParametrizedStyles.kt |
Detects and deletes invalid mention spans. |
android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputViewManager.kt |
Exposes the Android prop setter. |
.playwright/tests/mentions.spec.ts |
Tests default behavior, deletion, and boundary typing. |
Review effort: Balanced
- Android: skip mention spans the nested watcher pass already removed, which crashed when a deletion touched two mentions - iOS: apply the prop before defaultValue, and check the text of mentions that end up touching each other - web: also compare the mention text, so same-length edits count
This branch has not been 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.


Summary
Closes #855.
Adds a
removeInvalidMentionContentprop. When it'strue, any change to the text of an inserted mention (typing inside it, deleting part of it, autocorrect) removes the whole mention. When it'sfalse(the default), nothing changes: the text stays and is no longer a mention.iOS and web already have a check for "this mention's text no longer matches", and the prop changes what happens there. Android gets a small one next to its existing stale-span handling:
MentionStyle.handleExistingMentionsdeletes the text instead of removing the attribute. Text typed inside a mention doesn't get the mention attribute, so it splits the mention into two runs with the same params; those are deleted together with the typed text in between.ParametrizedStyles.afterTextChangedchecks the mention spans and deletes a span whose text no longer matches. I didn't branch insidedetectActiveMention, because it only looks at the word around the cursor and misses mentions whose text has no indicator.removeMentionMarksIfSpansResizeddeletes the range instead of removing the mark.On all three: the space after the mention stays, the cursor ends up where the mention started, and edits right before or after a mention don't count. One iOS-only case: a mention loaded from HTML whose
textattribute doesn't match its content is removed on load. That's the same check that already strips such mentions on iOS today; Android and web don't check on load.Two choices you may want differently:
setMentionreuses a space that's already there, so the space can't always be counted as part of the mention.Test Plan
Example app (Dev Screen,
removeInvalidMentionContentbutton) or/test-mentionson web:@Jand pick a user.<mention>.main.Automated:
removeMentionMarksIfSpansResized.test.tscovers both modes, editing at the edge, and two mentions changed in one edit.mentions.spec.ts(default behaviour, typing inside, backspace inside, typing right after).I checked steps 1–5 by hand on the iOS simulator (iPhone 17 Pro, iOS 26.5), the Android emulator (Pixel 5, Gboard) and Chrome.
I put the toggle on the Dev Screen rather than the Test Screen so the Test Screen's Maestro screenshots don't change.
Screenshots / Videos
iOS
ios.mp4
Android
android.mp4
Web
web.webm
Compatibility
Checklist
Web E2E pass locally in Chrome, except
mention renders correctly, which is a screenshot test that needs the Docker browser. I couldn't run the Maestro/Argent mobile E2E.