Skip to content

fix(android): block mention events when cursor is inside a finalized mention span#489

Open
Jianlong-Nie wants to merge 1 commit intosoftware-mansion:mainfrom
Jianlong-Nie:fix/android-mention-spurious-trigger
Open

fix(android): block mention events when cursor is inside a finalized mention span#489
Jianlong-Nie wants to merge 1 commit intosoftware-mansion:mainfrom
Jianlong-Nie:fix/android-mention-spurious-trigger

Conversation

@Jianlong-Nie
Copy link

@Jianlong-Nie Jianlong-Nie commented Mar 18, 2026

Problem

On Android, after a mention is finalized (user selects from the suggestion list), typing new characters after the mention continues to trigger the mention suggestion list.

Root cause: afterTextChangedMentions uses a previousWord fallback — when the cursor moves to a new word after the mention, it looks back and finds @username as the previous word, which matches mentionRegex, causing onMention to fire again even though the mention span is already resolved.

Fix

After determining the candidate range [finalStart, finalEnd], scan for EnrichedInputMentionSpan across the full range:

  • Span text matches buffer → mention is intact, call endMention() and return. This blocks the spurious event when the cursor is in a word adjacent to a finalized mention span (mirrors iOS conflictingStyles behaviour).
  • Span text has diverged (user edited inside it) → remove the stale span and record mentionStart = spanStart so setMentionSpan can replace the correct range when the user picks a new mention.

Changes

  • android/…/styles/ParametrizedStyles.kt — reworked afterTextChangedMentions span-check logic.

before:

MicrosoftTeams-video.-.2026-03-17T140027.449.1.mp4

after:

e9dd6268b745fccdc913bbf0dc4ed570.mp4

…mention span

Mirror iOS conflicting-styles behaviour in afterTextChangedMentions:
- After determining the candidate range [finalStart, finalEnd], scan for
  EnrichedInputMentionSpan across the full range (not just currentWord).
- If the span text matches the buffer, the mention is intact — call
  endMention() to suppress the event (fixes spurious mention list pop-up
  when a pre-filled @mention is loaded, e.g. in reply flows).
- If the span text has diverged (user edited inside it), remove the stale
  span and record mentionStart = spanStart so setMentionSpan can later
  replace the correct range when the user picks a new mention.
@kacperzolkiewski
Copy link
Collaborator

Hi @Jianlong-Nie,
In your second video, it looks like it’s not working correctly. Deleting characters after @ should still emit the event just like it does in Slack.

@Jianlong-Nie
Copy link
Author

Jianlong-Nie commented Mar 18, 2026

In your second video, it looks like it’s not working correctly. Deleting characters after @ should still emit the event just like it does in Slack.

If you take a closer look, it does trigger — in the video, it fires when deleting the fourth or fifth character. I’ve added some throttling here, so it’s not triggered immediately on every single change. @kacperzolkiewski

@kacperzolkiewski
Copy link
Collaborator

kacperzolkiewski commented Mar 18, 2026

@Jianlong-Nie Thank you for your contribution!
We’d like community fixes to follow the issue → PR flow, so could you please create an issue describing the problem this PR addresses and link it here?
I had to run it locally and test it myself to fully understand the issue, so a clearer description would really help reviewers.

@Jianlong-Nie
Copy link
Author

Linking the issue as requested: fixes #490

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