Skip to content

fix(android): preserve inline styles during IME composition - #737

Open
woosanggyu wants to merge 1 commit into
software-mansion:mainfrom
woosanggyu:fix/android-preserve-inline-styles-during-ime-composition
Open

fix(android): preserve inline styles during IME composition#737
woosanggyu wants to merge 1 commit into
software-mansion:mainfrom
woosanggyu:fix/android-preserve-inline-styles-during-ime-composition

Conversation

@woosanggyu

Copy link
Copy Markdown

Summary

Fixes #734.

On Android, predictive keyboards replace the entire active composing word on each setComposingText call. When an inline style was toggled off in the middle of that word, the replacement discarded enriched inline spans that belonged to the unchanged prefix.

This change:

  • enables inline-style preservation only when a style is toggled during an active IME composition;
  • snapshots enriched inline spans from the current composing range before setComposingText or commitText;
  • restores spans only over unchanged prefix and suffix ranges, keeping newly typed text consistent with the current style state;
  • clears preservation state when the composition is committed or finished; and
  • queries all enriched inline spans in one pass to avoid overhead during normal typing.

The change is limited to the Android text input implementation.

Test Plan

Manual verification in the example Android app with Gboard predictive text / suggestions enabled:

  1. Type abc.
  2. Toggle bold on and type def without a space.
  3. Toggle bold off and type ghi without a space.
  4. Verify that only def remains bold.
  5. Repeat with italic, underline, and strikethrough.
  6. Commit the word and verify that the earlier inline styles are still preserved.

Automated checks:

  • Android Kotlin compilation passed.
  • Android lint and formatting checks passed.
  • yarn lint passed.
  • yarn typecheck passed.
  • yarn test --maxWorkers=2 passed (415 tests).

Screenshots / Videos

See the reproduction video in #734. The fix does not change layout or visual design.

Compatibility

OS Implemented
iOS
Android
Web

Checklist

  • E2E tests are passing (not run; the regression requires an active predictive-keyboard composing region)
  • Required E2E tests have been added (not applicable to the current automated input environment)

Copilot AI review requested due to automatic review settings July 31, 2026 03:10

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 fixes an Android-only IME composition edge case where predictive keyboards (via repeated setComposingText) can drop previously-applied enriched inline style spans when an inline style is toggled mid-word. The change adds targeted span snapshot/restore logic in the Android InputConnection wrapper so only unchanged parts of the composing word keep their prior inline styling.

Changes:

  • Adds an inline-style restoration helper to reapply a specific inline style span over a given range when missing.
  • Tracks when inline-style preservation should run (only after an inline style is toggled during an active composing region).
  • Snapshots inline spans inside the composing range before setComposingText / commitText, then restores them over the unchanged prefix/suffix, clearing state when composition is committed/finished.

Reviewed changes

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

File Description
android/src/main/java/com/swmansion/enriched/textinput/styles/InlineStyles.kt Adds restoreStyleOnRange to reapply a specific inline style span when absent.
android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt Stores the wrapped InputConnection and triggers preservation when toggling inline styles.
android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputConnectionWrapper.kt Implements composing-range snapshot + restore around IME updates and clears preservation state appropriately.

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

@hejsztynx
hejsztynx self-requested a review July 31, 2026 10:26
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.

[Android] Inline styles are stripped from previously-styled text when toggling a style OFF mid-word with predictive text enabled

2 participants