Skip to content

fix: various mentions bugs and inconsistencies between platforms#637

Open
hejsztynx wants to merge 16 commits into
mainfrom
@ksienkiewicz/fix-mention-events
Open

fix: various mentions bugs and inconsistencies between platforms#637
hejsztynx wants to merge 16 commits into
mainfrom
@ksienkiewicz/fix-mention-events

Conversation

@hejsztynx

Copy link
Copy Markdown
Collaborator

Summary

There were various bugs and inconsistencies with mentions functionalities across every platform.

Mainly it wasn't handled properly when you switched directly between different mentions, which caused improper event emission and the lists stayed visible - documented in the videos section

iOS:

  • events not emitted when switching directly between mentions
  • duplicated onChange events when just moving a cursor across a mention
  • _recentInputString was not updated if no onChangeText prop was given

Android:

  • events not emitted when switching directly between mentions
  • on selection changes, the mentions were not reanalyzed and no events were emitted
  • when setMention a duplicated space was inserted if there already was one

Web:

  • refactor on the event subscription hook for consistency
  • mention query was evaluated to a cursor position, not the whole written mention, which produced leftover text when inserting a mention
  • unnecessarily considered a finalized mention into the query
  • events not emitted when switching directly between mentions
  • when setMention a duplicated space was inserted if there already was one

Example apps:

  • updated example apps with more idiomatic code. Earlier onChange mention event would handle popup list opening - something what onStart is for

Test Plan

Follow the text written in the attached videos, play around with selection changes, all events should emit correctly and the lists should function as expected.

Screenshots / Videos

(all platforms) events not emitting when switching between mentions

Screen.Recording.2026-05-29.at.22.47.12.mov

(web) incorrect query evaluation and inserting, doubled space

Screen.Recording.2026-06-14.at.18.15.19.mov

Compatibility

OS Implemented
iOS
Android
Web

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

Copilot AI review requested due to automatic review settings June 14, 2026 16:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses multiple cross-platform inconsistencies and edge-case bugs in “mentions” handling (trigger lifecycle events, selection-driven re-analysis, insertion behavior) across iOS, Android, and Web, and updates the example apps + E2E coverage to reflect the intended event semantics.

Changes:

  • Web: refactors mention event handling into a React hook, fixes trigger range/query evaluation, and avoids inserting duplicate trailing spaces when setting a mention.
  • iOS/Android: improves mention lifecycle event emission when switching directly between mentions, avoids duplicate events, and aligns “recent input” tracking to support selection-driven mention detection.
  • E2E: adds Playwright coverage for switching between different mention triggers and validating end/start ordering.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/web/pmPlugins/MentionPlugin/useMentionEvents.ts New React hook to subscribe to mention trigger + detected-mention events.
src/web/pmPlugins/MentionPlugin/subscribeMentionEvents.ts Removes the prior imperative subscribe/unsubscribe helper.
src/web/pmPlugins/MentionPlugin/setMention.ts Avoids inserting an extra trailing space when setting a mention.
src/web/pmPlugins/MentionPlugin/makeMentionPluginState.ts Updates how the mention query range is computed (to word end) and adjusts indicator detection behavior.
src/web/pmPlugins/MentionPlugin/index.ts Exports the new hook instead of the removed subscribe helper.
src/web/EnrichedTextInput.tsx Switches mention event wiring from subscribeMentionEvents to useMentionEvents.
ios/styles/MentionStyle.mm Fixes mention event emission ordering / deduping and avoids inserting duplicate spaces on mention insert.
ios/EnrichedTextInputView.mm Ensures _recentInputString stays in sync even if no onChangeText emitter exists.
apps/example/src/hooks/useEditorState.ts Updates example mention popup behavior to use start/end events rather than change events.
apps/example-web/src/testScreens/TestMentions.tsx Extends the web test screen UI to expose last end-event indicator for assertions.
apps/example-web/src/App.tsx Updates example popup-open behavior to align with start/end mention events.
android/src/main/java/com/swmansion/enriched/textinput/watchers/EnrichedTextWatcher.kt Tracks recentInputString to support selection-only mention analysis.
android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedSelection.kt Re-analyzes mentions on selection changes when text hasn’t changed.
android/src/main/java/com/swmansion/enriched/textinput/styles/ParametrizedStyles.kt Adds selection-change mention detection path and renames internal detection helper.
android/src/main/java/com/swmansion/enriched/textinput/events/OnMentionEvent.kt Disables event coalescing so end/start/change bursts aren’t collapsed.
android/src/main/java/com/swmansion/enriched/textinput/events/MentionHandler.kt Ensures correct end→start→change sequence when switching mentions; improves dedupe logic.
android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt Adds recentInputString storage on the view.
.playwright/tests/mentions.spec.ts Adds E2E test for switching between different mentions and verifying lifecycle events.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/web/pmPlugins/MentionPlugin/useMentionEvents.ts
Comment thread src/web/pmPlugins/MentionPlugin/setMention.ts
Comment thread src/web/pmPlugins/MentionPlugin/index.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Comment thread src/web/pmPlugins/MentionPlugin/useMentionEvents.ts
Comment thread ios/styles/MentionStyle.mm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants