Batch commands together when editing text in LegacyPlatformTextInputServiceAdapter#2722
Merged
Batch commands together when editing text in LegacyPlatformTextInputServiceAdapter#2722
Conversation
…tInputServiceAdapter
igordmn
approved these changes
Jan 27, 2026
ASalavei
approved these changes
Jan 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The skiko implementation of
LegacyPlatformTextInputServiceAdaptercurrently runs eachEditCommandimmediately as it is requested.This is problematic because:
BasicTextField(TextFieldState)(inTextInputSession.skiko.kt) which buffers the commands inTransformedTextFieldState.editUntransformedTextAsUser.BasicTextField(TextFieldValue)it causes calls toonValueChangewith intermediate states. Combined with theif (value != it)check inBasicTextField(TextFieldValue)before calling the upstreamonValueChangethis makes the final state (even more) dependent on the order and timing of recompositions. See the scenario detailed below for an example.This PR changes the behavior of
LegacyPlatformTextInputServiceAdapterto instead buffer commands and commit them together once the editing block returns.This change also semi-accidentally fixes CMP-9380 Wubi input method; first letter vanishes on 2nd keystroke. The issue there is that for Wubi input, the JVM sends each composing
InputMethodEventtwice. Each such an event tells us the committed text is empty, and adds a character to the composing text. For example, when the user presses 'q', the event sent isInputMethodEvent[committed="", composing="q"]. For each such eventDesktopTextInputService2performs two editing commands:When two such events are sent, with a recomposition between them, the state changes as follows:
InputMethodEvent[committed="", composing="q"]is received byDesktopTextInputService2, and it:onValueChange.onValueChange. The hoisted value is nowTextFieldValue(text='q', selection=TextRange(1, 1), composition=TextRange(0, 1))BasicTextFieldwith the new hoisted value.InputMethodEvent[committed="", composing="q"]is received byDesktopTextInputService2, and it:onValueChange, changing the hoisted value toTextFieldValue(text='', selection=TextRange(0, 0), composition=null)TextFieldValue(text='q', selection=TextRange(1, 1), composition=TextRange(0, 1))toonValueChange, but actually fails to do so because this value is identical to the last recomposed value inBasicTextFieldwhich only calls the "upstream"onValueChangeif the value is actually changed:So the final state ends up being the value delivered in 3.1, which is just the empty text value.
When instead each pair of changes (commit + setComposition) are grouped:
onValueChangeis not called in step 3.1. This is the crucial difference.onValueChangeis attempted to be called in step 3.2, but isn't because the new value is identical to the recomposed one.Altogether, the final state is the correct
TextFieldValue(text='q', selection=TextRange(1, 1), composition=TextRange(0, 1))Fixes https://youtrack.jetbrains.com/issue/CMP-9380
Testing
Tested manually and added unit tests.
Release Notes
Fixes - Desktop
(Basic)TextField(TextFieldValue).