Skip to content

Fix Android multiline TextBox IME offsets - #21680

Merged
MrJul merged 2 commits into
AvaloniaUI:mainfrom
AlexSCcon:android-multiline-textbox-ime-master
Jul 24, 2026
Merged

Fix Android multiline TextBox IME offsets#21680
MrJul merged 2 commits into
AvaloniaUI:mainfrom
AlexSCcon:android-multiline-textbox-ime-master

Conversation

@AlexSCcon

Copy link
Copy Markdown
Contributor

What does the pull request do?

Fixes Android multiline TextBox IME offset handling.

This is a minimal patch related to #20232. The issue appears when Android IME operations such as selection updates, newline input, and backspace interact with multiline TextBox content.

This was originally reproduced and tested against 12.0.5. This PR targets master as requested, and may be suitable for a 12.0.x backport.

What is the current behavior?

TextBoxTextInputMethodClient reports SurroundingText and Selection using offsets relative to the current visual text line.

On Android multiline TextBox input, this can cause IME operations to target the wrong document offsets after the caret moves onto later lines. In practice this shows up as backspace/newline/caret drift in multiline text.

What is the updated/expected behavior with this PR?

The IME client now reports full-document surrounding text and document-wide selection offsets.

This keeps Android IME selection, deletion, and composition operations aligned with the actual TextBox document positions in multiline text.

Validation:

  • Added unit tests for multiline SurroundingText.
  • Added unit tests for setting Selection with document offsets.
  • Verified Avalonia.Controls.UnitTests.TextBoxTests passes: 164 passed, 0 failed.

How was the solution implemented (if it's not obvious)?

TextBoxTextInputMethodClient.SurroundingText now returns the full TextBox.Text instead of extracting the current text line from TextLayout.

TextBoxTextInputMethodClient.Selection now gets and sets TextBox.SelectionStart / TextBox.SelectionEnd directly as document offsets, instead of translating through the current line start.

This also replaces the anonymous CaretBoundsChanged subscription with a stored event handler so the old presenter can be unsubscribed correctly.

Checklist

Breaking changes

None.

Obsoletions / Deprecations

None.

Fixed issues

Fixes #20232

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0067015-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@AlexSCcon
AlexSCcon marked this pull request as ready for review July 1, 2026 07:58
@MrJul MrJul added bug os-android backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Jul 1, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0067017-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul
MrJul requested a review from Gillibald July 3, 2026 07:56
@MrJul MrJul added backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch and removed backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Jul 9, 2026
@SitronX

SitronX commented Jul 14, 2026

Copy link
Copy Markdown

I was curious so i tested it with 12.2.199-cibuild0067392-alpha. And the jumping caret issue is still present. When i have 5 line text box and i am editing second line and at the end, the next space or character jumps still to wrong line and position. In original related issue, i had video where it is visible what happens.

Ok i tested exactly the version of the package the bot mentioned, i previously thought nightlies are working differently. And it fixes the issue! So glad somebody found time to deal with this, hopefully this will get merged to official releases soon 👏

@AlexSCcon

Copy link
Copy Markdown
Contributor Author

I was curious so i tested it with 12.2.199-cibuild0067392-alpha. And the jumping caret issue is still present. When i have 5 line text box and i am editing second line and at the end, the next space or character jumps still to wrong line and position. In original related issue, i had video where it is visible what happens.

Ok i tested exactly the version of the package the bot mentioned, i previously thought nightlies are working differently. And it fixes the issue! So glad somebody found time to deal with this, hopefully this will get merged to official releases soon 👏

Thanks, glad to hear that it worked! It completely broke my app so I decided to spent a bit of time to see if I could fix it rather than try hacky alternatives. Hope it makes it in the next release also so I can have by app off a alpha build!

@SitronX

SitronX commented Jul 21, 2026

Copy link
Copy Markdown

Thanks, glad to hear that it worked! It completely broke my app so I decided to spent a bit of time to see if I could fix it rather than try hacky alternatives. Hope it makes it in the next release also so I can have by app off a alpha build!

@AlexSCcon

Yes. I am just extremely suprised that this - i would say very critical bug breaking core functionality, wasnt caught earlier by devs themselves. It frustated me so much and i cant imagine deploying mobile app to normal users with how textbox worked on mobile.

Sadly so many things are open here that this issue flewed under the radar for so long. Hopefully it will get mergerged as soon as possible, so we can update to new official version of avalonia.

@Gillibald Gillibald 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.

Since there is no better way at the moment to expose the full text buffer on demand I am aproving this change

LGTM

@MrJul
MrJul enabled auto-merge July 22, 2026 17:36
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0067707-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul
MrJul added this pull request to the merge queue Jul 24, 2026
Merged via the queue into AvaloniaUI:main with commit 561b9a3 Jul 24, 2026
9 checks passed
MrJul added a commit that referenced this pull request Jul 29, 2026
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextBox with TextWrapping enabled is extremely buggy on Android

5 participants