Visitar URL original
fix(textbox): Fix IME and touch editing on Android browsers (backport #25804) by mergify[bot] · Pull Request #25984 · unoplatform/uno · GitHub
Skip to content

fix(textbox): Fix IME and touch editing on Android browsers (backport #25804) - #25984

Merged
ajpinedam merged 2 commits into
servicing/6.8from
mergify/bp/servicing/6.8/pr-25804
Nov 4, 2026
Merged

ajpinedam merged 2 commits into
servicing/6.8from
mergify/bp/servicing/6.8/pr-25804

Conversation

@mergify

@mergify mergify Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: closes unoplatform/kahua-private#548

PR Type:

🐞 Bugfix

What changed? 🚀

On Skia WebAssembly, a TextBox on an Android tablet (Chrome) misbehaved with the soft keyboard and with touch:

  • IME composition repeated text, lost spaces and desynced the caret.
  • Double-tapping near punctuation selected the wrong word or moved the caret to the end.
  • Quick taps on adjacent lines counted as a double-tap.

Testing on a real Galaxy Tab A8 (Chrome 155, Gboard 18.5 and Samsung Keyboard) turned up more bugs, fixed here too.

The PR has two commits, each of which builds on its own:

  • fix(wasm): IME composition, soft-keyboard keys and edits the browser applied (WebAssembly). It includes the TextBoxCore/RichEditBox IME-host changes those need.
  • fix(textbox): touch selection under the Android and iOS conventions, on every Skia host.

IME composition (WebAssembly)

  • The hidden <input>/<textarea> is now the source of truth for composition text in every browser. The browser applies the text and the TextBox follows it (textAlreadyApplied), as on Skia Android. A composition that doesn't change the text (an IME re-selecting a word) is ignored.
  • compositionend no longer swallows the next input event. That event is a separate edit, such as Gboard's space after a word.
  • A TextBox edit made during a composition (a TextChanging filter, MaxLength) is reconciled when the composition ends, instead of restarting the IME.
  • A multi-line TextBox's textarea uses \n where the TextBox uses \r. Text that differs only by that no longer counts as a TextBox edit, which used to send the caret to 0 mid-sentence.
  • The input's own selection restore, after its value is assigned, no longer hijacks the next caret move by the keyboard. On Android Chrome, emptying the value fires no selectionchange.

Soft-keyboard keys (WebAssembly)

  • Samsung Keyboard sends Backspace, Delete, arrows and Enter with an empty KeyboardEvent.code.
    • Unmodified code-less Backspace/Delete are now applied by the browser, like other soft-keyboard keys. A deletion the TextBox made itself left the keyboard's copy of the text stale, so its next suggestion replaced the wrong range.
    • Other code-less named keys are mapped from key, so arrows and Enter reach the TextBox. Character keys aren't, since FromKey would turn - or . into numpad keys.
  • An Android Enter raises a single KeyUp.

Text the browser applied (WebAssembly)

  • It is now undoable as one typing run, like keys the TextBox handles. An edit the TextBox refuses records no undo step.
  • Its text change puts the caret where the input left it, without a SelectionChanged at 0 first.
  • A read-only TextBox refuses it.
  • When the TextBox rejects an edit (MaxLength, BeforeTextChanging), the caret goes back to where the edit started instead of 0.
  • App exceptions thrown from these browser callbacks are logged and reported through Application.UnhandledException instead of escaping into the DOM handlers.

Touch selection (Android and iOS touch conventions, all Skia hosts)

  • A double-tap selects the word under the finger, including when the finger is on the trailing half of a letter next to punctuation. The second tap may land on the insertion handle.
  • Two quick taps count as a double-tap only within 24 DIP and on the same line, so taps on adjacent lines move the caret.
  • The insertion handle's thumb hangs over the line below the caret. A tap there that comes as quickly after the tap that placed the caret as a double-tap's second tap moves the caret to that line. A later tap on the handle keeps the caret and shows the paste flyout, as on native Android.
  • A touch just below or above the text (the box's padding, under the last line) uses the nearest line by X instead of the end of the text. This covers taps, long-press, double-tap and the iOS caret drag. One helper now does this line clamp for touch, the selection-handle drag and the caret drag.
  • The Desktop convention and mouse input are unchanged.

Validation

  • Runtime, Skia desktop: 1457 tests across Given_TextBox, Given_RichEditBox, Given_TextBlock, Given_PasswordBox and Given_ImeSessionCoordinator. 4 fail, and all 4 also fail on this machine without these changes: When_Multiline_Pointer_Tap, When_Pointer_RightClick_Selection, TextBlock.When_IsTextSelectionEnabled_CRLF, and RichEditBox.When_Idle_Caret_Stops_Blinking_After_Timeout (checked on the base commit). The When_Touch_* and gripper tests (71) also pass on the touch commit itself.
  • Runtime, Skia WebAssembly (headless Chrome): 119/119 across the keyboard source, every Given_TextBox.When_Browser* and When_Touch* test, Given_RichEditBox.When_Wasm* and Given_AccessibleTextBox (which runs with accessibility on). On the IME commit alone, the 87 browser and accessibility tests pass.
  • Tests fail before the fix: every new test failed without its fix. This was checked with a desktop build with the fix disabled, WebAssembly builds with the C# fixes reverted, and the compiled runtime JS patched (or swapped for the previous one) to undo the TS fixes.
  • Real tablet:
    • Typing, Backspace, suggestions and re-composition with Samsung Keyboard and Gboard match what Chrome's own fields do on the same device.
    • The touch cases were checked with touches sent over Chrome remote debugging, not a physical finger.
    • Gboard never composed on this device, even in Chrome's own fields, so Samsung Keyboard exercised the composition path.

Known follow-ups, not in this PR

  • TextCompositionStarted/Changed are raised before Text contains the composition, on WebAssembly and on Skia Android.
  • Not yet run on a real device: Safari, Firefox and Samsung Internet.
  • Before merge: a manual pass with desktop CJK IMEs (Microsoft IME Japanese in Chrome on Windows, Pinyin in Safari on macOS).

PR Checklist ✅

🤖 Generated with Claude Code


This is an automatic backport of pull request #25804 done by [Mergify](https://mergify.com).

@mergify mergify Bot added the conflicts Automated merge hit conflicts label Nov 3, 2026
@mergify

mergify Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Cherry-pick of e1991c2 has failed:

On branch mergify/bp/servicing/6.8/pr-25804
Your branch is up to date with 'origin/servicing/6.8'.

You are currently cherry-picking commit e1991c2.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   src/Uno.UI.Runtime.Skia.WebAssembly.Browser/Devices/Input/BrowserKeyboardInputSource.cs
	modified:   src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Input/Given_BrowserKeyboardInputSource.cs
	modified:   src/Uno.UI/UI/Xaml/Controls/TextBox/Extensions/ImeCompositionEventArgs.skia.cs

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	both modified:   src/Uno.UI.Runtime.Skia.WebAssembly.Browser/UI/Xaml/Controls/TextBox/BrowserInvisibleTextBoxViewExtension.cs
	both modified:   src/Uno.UI.Runtime.Skia.WebAssembly.Browser/UI/Xaml/Controls/TextBox/WasmImeTextBoxExtension.cs
	both modified:   src/Uno.UI.Runtime.Skia.WebAssembly.Browser/ts/Runtime/BrowserInvisibleTextBoxViewExtension.ts
	deleted by us:   src/Uno.UI.RuntimeTests/Microsoft/UI/Xaml/Automation/Given_AccessibleTextBox.cs
	deleted by us:   src/Uno.UI.RuntimeTests/Microsoft/UI/Xaml/Controls/Given_ImeSessionCoordinator_RootOwnership.skia.cs
	deleted by us:   src/Uno.UI.RuntimeTests/Microsoft/UI/Xaml/Controls/Given_RichEditBox.Ime.skia.cs
	both modified:   src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBox.skia.cs
	deleted by us:   src/Uno.UI/UI/Xaml/Controls/RichEditBox/RichEditBox.IME.cs
	deleted by us:   src/Uno.UI/UI/Xaml/Controls/TextBox/IImeSessionHost.cs
	deleted by us:   src/Uno.UI/UI/Xaml/Controls/TextBox/ImeSessionCoordinator.cs
	both modified:   src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.IME.skia.cs
	both modified:   src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.skia.cs
	deleted by us:   src/Uno.UI/UI/Xaml/Controls/TextBoxCore/TextBoxCore.cs

Cherry-pick of 6d4c191 has failed:

On branch mergify/bp/servicing/6.8/pr-25804
Your branch is ahead of 'origin/servicing/6.8' by 1 commit.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit 6d4c191.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBox.skia.cs
	new file:   src/Uno.UI/UI/Xaml/Documents/ParsedTextExtensions.cs

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	both modified:   src/Uno.UI/UI/Xaml/Controls/Primitives/TextSelectionGripperPresenter.skia.cs
	deleted by us:   src/Uno.UI/UI/Xaml/Controls/RichEditBox/RichEditBox.uno.cs
	both modified:   src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.cs
	both modified:   src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.skia.cs
	deleted by us:   src/Uno.UI/UI/Xaml/Controls/TextBoxCore/TextBoxCore.CaretDrag.cs
	deleted by us:   src/Uno.UI/UI/Xaml/Controls/TextBoxCore/TextBoxCore.pointers.cs

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@github-actions github-actions Bot added the area/skia ✏️ Categorizes an issue or PR as relevant to Skia label Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

WinAppSDK sync generator drift detected on 0cc4baa

The Uno.WinAppSDKSyncGenerator produced changes that are not committed on this PR.

To apply automatically (PRs from branches in this repo only): comment /apply-sync-gen on this PR and a bot will push chore: Sync generator run to the head branch.

To apply manually (required for PRs from forks):

  1. Download the sync-generator-patch artifact from this run.
  2. In your local checkout of the PR branch:
    git apply sync-generator.patch
    git add -A
    git commit -m "chore: Sync generator run"
    git push
    

Or re-run the generator locally on Windows via build\run-api-sync-tool.cmd.

@ajpinedam
ajpinedam force-pushed the mergify/bp/servicing/6.8/pr-25804 branch from 0cc4baa to ebdab74 Compare November 4, 2026 03:55
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 243499 did not find any UI Test snapshots differences.

@mergify

mergify Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@ajpinedam ajpinedam removed the conflicts Automated merge hit conflicts label Nov 4, 2026
@ajpinedam
ajpinedam merged commit 6036f29 into servicing/6.8 Nov 4, 2026
43 checks passed
@ajpinedam
ajpinedam deleted the mergify/bp/servicing/6.8/pr-25804 branch November 4, 2026 11:12
mikernet added a commit to Singulink/uno that referenced this pull request Nov 14, 2026
Takes Uno's servicing/6.8 from 6951c2c up to 5254ace (42 pull
requests). Conflicts, by area:

IME and TextBox (unoplatform#25984, backport of unoplatform#25804; unoplatform#25952, backport of unoplatform#25619;
unoplatform#25976, backport of unoplatform#25818)
- Takes upstream's composition design (unoplatform#25804): the browser's input is
  the source of truth for the text, compositions included. This drops
  the composition parts of the unoplatform#24502 port (90746b8): its
  TypeScript composition handling, the StartIndex/TextChangePending
  event arguments, the IsReadOnly forwarding to the hidden input, and
  its Given_TextBox.BrowserSoftKeyboard tests.
- Keeps the non-IME browser fixes on top of it, in the form their
  master pull requests have on unoplatform#25804: Enter raised once per press and
  tracked by key code (unoplatform#25174, with Given_TextBox.BrowserEnterKey from
  master in place of the Enter tests that lived in the dropped file),
  the iOS refocus on tap (unoplatform#25185), pastes without text and isIOS from
  BrowserInputHelper.
- Moves the unoplatform#26005 MaxLength fixes onto unoplatform#25804's native input path, as
  master has them: a refused browser edit keeps the TextBox's selection,
  TextBoxView.UpdateTextFromNative reports whether the edit went in, and
  the IME keeps its range on the applied text (master be85699, which
  d226897 had ported onto the unoplatform#24502 IME). Adds that commit's browser
  and platform-applied IME tests.
- TextBox.pointers.skia.cs: upstream's file (unoplatform#25619 iOS touch editing,
  unoplatform#25818, unoplatform#25804), with the unoplatform#25126 port (the hold acts when it starts,
  a touch right-tap keeps the caret) in the form master's unoplatform#25126 branch
  has it on unoplatform#25619, including focusing before the iOS hold timer acts
  and its iOS not-focusable test.

Pointers (unoplatform#25976, backport of unoplatform#25818)
- Tapped and RightTapped are raised once the PointerReleased bubbled
  (unoplatform#25818), with the unoplatform#25732 port's window coordinates (2-argument
  routed event args, RawPosition for ContextRequested), as master's
  unoplatform#25732 branch has them.
- The release wrapper of unoplatform#25818 keeps the unoplatform#25126 port's
  StopContextMenuTimer at the start of the release.

DependencyObject (unoplatform#26142, backport of unoplatform#26123)
- Takes upstream, then the code of unoplatform#25839 (97a2f17), which replaces
  this branch's unoplatform#25102 ports (800247f, be41da6, fd40bf9,
  7546379). DependencyObjectStore.Binder.cs, .alc.cs,
  Application.Alc.cs, ResourceDictionary.alc.cs and their tests now
  match unoplatform#25839; this drops 800247f's own
  SingleParentNonFE_Parent_Removes_Value_Then_Next_Parent_Starts_Clean
  test, which unoplatform#25839 doesn't have.

Imaging (unoplatform#25597, unoplatform#25915, unoplatform#25911, unoplatform#25897)
- Keeps this branch's side: it has the later forms of these fixes
  (unoplatform#25124, unoplatform#25559, unoplatform#25633 and unoplatform#26370 ports), where upstream has the
  6.8-only unoplatform#25597 design and earlier snapshots. Upstream's shared
  download, IgnoreImageCache and failed-load fixes are covered by
  SharedImageDecode. Adds upstream's When_Source_Outlives_Brushes test.

ToolTip (unoplatform#26098, backport of unoplatform#25137 and unoplatform#26096)
- Keeps this branch's unoplatform#25137 port and adds unoplatform#26096 in master's form: the
  service releases only a ToolTip it opened, and leaves one the app
  opened during the show delay to the app. Keeps both sides' tests.

Flyout (unoplatform#26062, backport of unoplatform#26060)
- This branch had the same commits already; keeps the "Keep
  non-resizable flyouts in window" port and its tests.

Also removes a helper pair in Given_AccessibleTextBox that both sides
added.
mikernet added a commit to Singulink/uno that referenced this pull request Nov 14, 2026
Port of unoplatform#26434 (for unoplatform#26432), commits
faba3ed, 096daef, 8e2644f, b8d2189, edce6fa and
6939ef4, onto the unoplatform#25804 IME design this branch takes
from servicing/6.8 (unoplatform#25984).

- TextCompositionChanged for text the platform applied (WebAssembly,
  Skia Android) waits for the platform's text sync, and isn't raised
  for an update the TextBox refused. The Changed and no-commit Ended
  ranges are clamped to the text. Skia Android reports where its
  composing region starts.
- A composition ends when the hidden input is replaced or detached.
- An edit a BeforeTextChanging handler or a read-only TextBox refuses
  is written back to the input at once, ending the composition.
  Unlike master, this branch does the same for an edit MaxLength
  refuses or a TextChanging handler changes (see below).
- The hidden input is read-only with the TextBox.
- The caret goes back at once after a refused edit.

6.8 differences:
- Master's TextBoxCore.IME.cs, .Input.cs and .cs changes go to
  TextBox.IME.skia.cs, TextBox.skia.cs and TextBox.cs; events are raised
  on the TextBox itself. There is no RichEditBox IME, partial commit or
  CompositionCanceled on 6.8, so those parts are left out.
- Skia Android syncs through a new TextBox.UpdateTextFromNative, the
  6.8 counterpart of master's IImeSessionHost.UpdateTextFromNative. It
  raises the held TextCompositionChanged, and compares the editable's
  \n line breaks as the TextBox's \r, as master's
  IsNativeEchoOfCurrentText does.
- The read-only input follows TextBox.IsReadOnly through
  OnIsReadonlyChangedPartial; UpdateProperties, which only sets the
  enter key hint on 6.8, now also sets readOnly or re-enters the input.

With this branch's port of unoplatform#26005 (be85699):
- A refused platform sync puts the composition range back on the text
  that is there (unoplatform#26005), and raises TextCompositionChanged
  for that range only when it isn't the last range raised. The refused
  update's own range is never raised (unoplatform#26434).
- While a composition holds text the TextBox refused past MaxLength
  (reconciled when it ends), the hidden input's selectionchange isn't
  reported: its offsets are in that text, not in the TextBox's. Without
  this, the input's caret replaced the one edce6fa restores at once.
- ApplyNativeInput keeps unoplatform#26005's handling of a refused
  edit's pending selection.

Like Android's own LengthFilter (and this branch before the catch-up),
a composition edit the TextBox doesn't keep as the keyboard applied it
(MaxLength, a TextChanging filter, as well as BeforeTextChanging and
read-only) writes the TextBox's text back at once and ends the
composition, on WebAssembly and on Skia Android. Master keeps a
MaxLength or TextChanging refusal in the input until the composition
ends, so a CJK conversion can bring it back within the limit. Gboard
composes every Latin word, though, so the refused letters stayed in the
input for the whole word: its suggestions were built on them, and
Backspace deleted them before it reached the TextBox's text. A
conversion past the limit is lost here, as with Android's LengthFilter.
When_Browser_Ime_Composes_With_TextChanging_Filter (unoplatform#25804)
and the two conversion tests of unoplatform#26434 now expect that,
and When_Browser_Ime_Composes_Word_Past_MaxLength_Then_Input_Keeps_The_Limit
covers the Gboard case.

Adds tests for a refused Skia Android sync, \n line breaks in its sync,
and a refused composition followed by another before the dispatcher
runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/skia ✏️ Categorizes an issue or PR as relevant to Skia

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants