Repository navigation
Description
Current behavior 🐛
On Skia WebAssembly (and partly Skia Android), where the platform applies IME composition text itself and the TextBox follows its hidden input:
TextCompositionChangedis raised before its text is inText. TextBox and RichEditBox raise it when the platform reports the composition, before the text sync that follows. ItsStartIndex/Lengthpoint into text that isn't there yet: a handler readingText.Substring(e.StartIndex, e.Length)throwsArgumentOutOfRangeException, and a handler that moves focus to another TextBox makes the rest of that keystroke land in the other TextBox. Skia Android has the same order (the composition is reported inEndBatchEditbefore the text sync). On WebAssembly, aTextCompositionStartedorTextCompositionEndedhandler that moves focus has the same effect.- The composition's range can lie outside the text after a coercion or a deletion during the composition (a
TextChanginghandler that shortens the text), inTextCompositionChangedand inTextCompositionEndedfor a composition that ends without a commit. - The composition never ends when the hidden input is replaced or removed (the same TextBox re-entered with another focus state, as a tap does after keyboard focus; accessibility detaching the input):
IsComposingstaystrueandTextCompositionEndedis never raised. - An edit a
BeforeTextChanginghandler cancels during a composition stays in the hidden input until the composition ends. The keyboard keeps composing on the refused character, so later characters are refused too: typinga, a rejectedx, thenbleavesTextata. - A read-only TextBox still opens the soft keyboard on mobile browsers and lets the user type, each edit being reverted. WinUI doesn't show the touch keyboard for a read-only TextBox.
- After a refused plain (non-composition) edit, the caret goes back only a dispatcher tick later, so a fast next key lands where the refused edit left it ("abc", caret after "a", refused "x" then "y" gives "abyc").
Expected behavior 🎯
TextCompositionChangedis raised once its text is inText, afterTextChanging, and its range fits the text, as does that of a composition ending without a commit.TextCompositionStartedstays before the text, as on WinUI.- The browser's text doesn't land in a TextBox that a composition event handler moved focus to.
- A composition ends (
IsComposingfalse,TextCompositionEndedraised) when its input goes away. - An edit
BeforeTextChangingcancels is written back to the hidden input right away, so the keyboard continues from the TextBox's text. (EditsMaxLengthor aTextChanginghandler limit can stay reconciled when the composition ends, so a conversion can bring the composition back within the limit.) - A read-only TextBox doesn't bring up the soft keyboard; keyboard navigation, selection and copy keep working.
- The caret is back where a refused edit started before the next key.
Out of scope here: on Skia Android, TextCompositionEnded for a commit is raised before the committed text is synced, with the committed text's own range (not clamped, since clamping it to the stale text would cut a longer commit short).
How to reproduce it (as minimally and precisely as possible) 🔬
Skia WebAssembly, Chrome on Android (Gboard or Samsung Keyboard), or the runtime tests that replay the browser's event sequences on the hidden input:
<TextBox x:Name="tb" />tb.TextCompositionChanged += (s, e) => Debug.WriteLine(tb.Text.Substring(e.StartIndex, e.Length)); // throwsType a word with the soft keyboard. For 4: tb.BeforeTextChanging += (s, e) => e.Cancel = e.NewText.Contains('x'); then type axb. For 5: set IsReadOnly="True" and tap the TextBox.
Workaround 🛠️
Read the composed text in TextChanged instead of TextCompositionChanged; avoid cancelling edits in BeforeTextChanging during a composition.
Affected platforms 📱💻🖥️
WebAssembly, Android (Skia)
Uno.Sdk version (and other relevant versions) 📦
master after #25804 (Uno 7.0 dev)
IDE version 🧑💻
n/a
Anything else we need to know? 💬
#25804 lists "TextCompositionStarted/Changed are raised before Text contains the composition, on WebAssembly and on Skia Android" as a known follow-up. Analysis of the remaining cases: #24502 (comment)
Activity
fix(wasm): Fix IME composition order (port)