Skip to content

Commit 26d9d44

Browse files
authored
Fix Hangul output in iOS and in Safari (#2454)
Correct behaviour for Hangul input under certain circumstances Fixes [https://youtrack.jetbrains.com/issue/CMP-8773] ## Testing `./gradlew testWeb` ## Release Notes ### Fixes - Web - Mobile. Composite input. When a syllable block is created, a new block is added instead of replacing the old one
1 parent 8f52183 commit 26d9d44

3 files changed

Lines changed: 48 additions & 5 deletions

File tree

compose/ui/ui/src/webCommonW3C/kotlin/androidx/compose/ui/platform/DomInputStrategy.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ internal class DomInputStrategy(
7070
htmlInput as HTMLElementWithValue
7171
val deleteContentBackwardSize = htmlInput.selectionEnd - htmlInput.selectionStart
7272

73-
if (deleteContentBackwardSize > 0) {
74-
evt.deleteContentBackwardSize = deleteContentBackwardSize
75-
}
73+
evt.deleteContentBackwardSize = deleteContentBackwardSize
7674
nativeInputEventsProcessor.registerEvent(evt)
7775
}
7876
})

compose/ui/ui/src/webCommonW3C/kotlin/androidx/compose/ui/platform/NativeInputEventsProcessor.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ internal abstract class NativeInputEventsProcessor(
137137
val deleteSize = deleteContentBackwardSize
138138
if (deleteSize > 0) {
139139
add(DeleteSurroundingTextCommand(deleteSize, 0))
140+
} else if (deleteSize == 0) {
141+
// under specific circumstance previous symbol can be deleted while inputing new one
142+
// see https://youtrack.jetbrains.com/issue/CMP-8773
143+
add(BackspaceCommand())
140144
}
141145
}
142146
}

compose/ui/ui/src/webTest/kotlin/androidx/compose/ui/input/specs/СompositeInputTestSpec.kt renamed to compose/ui/ui/src/webTest/kotlin/androidx/compose/ui/input/specs/CompositeInputTestSpec.kt

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import androidx.compose.ui.events.keyEvent
2626
import kotlin.test.Test
2727
import kotlin.test.assertIs
2828
import org.w3c.dom.HTMLTextAreaElement
29+
import androidx.compose.ui.platform.InputEvent as InputEventDetailed
2930

3031
internal interface СompositeInputTestSpec : TextFieldTestSpec {
3132

@@ -77,6 +78,26 @@ internal interface ChromeCompositeInput : СompositeInputTestSpec {
7778
keyEvent(compositionInput, type = "keyup")
7879
)
7980
}
81+
82+
@Test
83+
fun `input hangul-hol`() = runApplicationTest {
84+
val textFieldValue = createApplicationWithHolder()
85+
eventsSequence(
86+
compositionStart(),
87+
keyEvent(key= "", code = "KeyG", keyCode = 229),
88+
beforeInput(inputType = "compositionStart", data = "null"),
89+
keyEvent(key= "", code = "KeyG", keyCode = 71, type = "keyup", isComposing = true),
90+
keyEvent(key= "", code = "KeyH", keyCode = 229),
91+
beforeInput(inputType = "insertCompositionText", data = ""),
92+
keyEvent(key= "", code = "KeyH", keyCode = 72, type = "keyup", isComposing = true),
93+
keyEvent(key= "", code = "KeyF", keyCode = 229),
94+
beforeInput(inputType = "insertCompositionText", data = ""),
95+
keyEvent(key= "", code = "KeyF", keyCode = 70, type = "keyup", isComposing = true),
96+
).sendToHtmlInput()
97+
98+
textFieldValue.awaitAndAssertTextEquals("")
99+
}
100+
80101
}
81102

82103
internal interface FirefoxCompositeInput : СompositeInputTestSpec {
@@ -147,7 +168,7 @@ internal interface WinCompositeInput : СompositeInputTestSpec {
147168
}
148169

149170
@Test
150-
fun `input korean-hol`() = runApplicationTest {
171+
fun `input hangul-hol`() = runApplicationTest {
151172
val textFieldValue = createApplicationWithHolder()
152173
compositionStart("g", "")
153174
.compositionUpdate("h", "")
@@ -216,6 +237,26 @@ internal interface IosCompositeInput : СompositeInputTestSpec {
216237
compositionEnd(typedKey),
217238
)
218239
}
240+
241+
@Test
242+
fun `input hangul-hol`() = runApplicationTest {
243+
val textFieldValue = createApplicationWithHolder()
244+
eventsSequence(
245+
keyEvent(key= "", code = "Unidentified", keyCode = 0),
246+
beforeInput("insertText", data = "", isComposing = false),
247+
keyEvent(key= "", code = "Unidentified", keyCode = 0, type = "keyup"),
248+
keyEvent(key= "", code = "Unidentified", keyCode = 0),
249+
beforeInput("deleteContentBackward", data = null, isComposing = false),
250+
beforeInput("insertText", data = "", isComposing = false),
251+
keyEvent(key= "", code = "Unidentified", keyCode = 0, type = "keyup"),
252+
keyEvent(key= "", code = "Unidentified", keyCode = 0),
253+
beforeInput("deleteContentBackward", data = null, isComposing = false),
254+
beforeInput("insertText", data = "", isComposing = false),
255+
keyEvent(key= "", code = "Unidentified", keyCode = 0, type = "keyup")
256+
).sendToHtmlInput()
257+
258+
textFieldValue.awaitAndAssertTextEquals("")
259+
}
219260
}
220261

221262
internal interface AndroidCompositeInput : СompositeInputTestSpec {
@@ -252,7 +293,7 @@ internal interface AndroidCompositeInput : СompositeInputTestSpec {
252293
}
253294

254295
@Test
255-
fun `input korean-hol`() = runApplicationTest {
296+
fun `input hangul-hol`() = runApplicationTest {
256297
val textFieldValue = createApplicationWithHolder()
257298
compositionStart("g", "")
258299
.compositionUpdate("h", "")

0 commit comments

Comments
 (0)