diff --git a/compose/foundation/foundation/src/webCommonW3C/kotlin/androidx/compose/foundation/text/TextFieldKeyInput.js.kt b/compose/foundation/foundation/src/webCommonW3C/kotlin/androidx/compose/foundation/text/TextFieldKeyInput.js.kt index 1badb8ae4d7e6..a26738c456aff 100644 --- a/compose/foundation/foundation/src/webCommonW3C/kotlin/androidx/compose/foundation/text/TextFieldKeyInput.js.kt +++ b/compose/foundation/foundation/src/webCommonW3C/kotlin/androidx/compose/foundation/text/TextFieldKeyInput.js.kt @@ -19,12 +19,16 @@ package androidx.compose.foundation.text import androidx.compose.ui.dom.domEventOrNull import androidx.compose.ui.input.key.KeyEvent import androidx.compose.ui.input.key.KeyEventType +import androidx.compose.ui.input.key.isCtrlPressed import androidx.compose.ui.input.key.isMetaPressed import androidx.compose.ui.input.key.type import org.w3c.dom.events.KeyboardEvent actual val KeyEvent.isTypedEvent: Boolean - get() = type == KeyEventType.KeyDown && !isMetaPressed && domEventOrNull?.isPrintable() == true + get() = type == KeyEventType.KeyDown + && !isMetaPressed + && !isCtrlPressed + && domEventOrNull?.isPrintable() == true private fun KeyboardEvent.isPrintable(): Boolean { return key.firstOrNull()?.toString() == key diff --git a/compose/ui/ui/src/webTest/kotlin/androidx/compose/ui/input/IsTypedEventTests.kt b/compose/ui/ui/src/webTest/kotlin/androidx/compose/ui/input/IsTypedEventTests.kt index cca9292415b9c..e8210c17febd4 100644 --- a/compose/ui/ui/src/webTest/kotlin/androidx/compose/ui/input/IsTypedEventTests.kt +++ b/compose/ui/ui/src/webTest/kotlin/androidx/compose/ui/input/IsTypedEventTests.kt @@ -59,6 +59,39 @@ class IsTypedEventTests { keyDownEvents.forEach { event -> event.assertIsNotTyped() } } + @Test + fun shortcutsWithCtrlOnlyAreNotTyped() { + val keyDownEvents = listOf( + keyDownEvent('c', metaKey = false, ctrlKey = true), + keyDownEvent('p', metaKey = false, ctrlKey = true), + keyDownEvent('v', metaKey = false, ctrlKey = true) + ) + + keyDownEvents.forEach { event -> event.assertIsNotTyped() } + } + + @Test + fun shortcutsWithMetaOnlyAreNotTyped() { + val keyDownEvents = listOf( + keyDownEvent('c', metaKey = true, ctrlKey = false), + keyDownEvent('p', metaKey = true, ctrlKey = false), + keyDownEvent('v', metaKey = true, ctrlKey = false) + ) + + keyDownEvents.forEach { event -> event.assertIsNotTyped() } + } + + @Test + fun altProducesATypedEvent() { + val keyDownEvents = listOf( + keyDownEvent('c', altKey = true), + keyDownEvent('p', altKey = true), + keyDownEvent('v', altKey = true) + ) + + keyDownEvents.forEach { event -> event.assertIsTyped() } + } + @Test fun functionalsAreNotTyped() { val keyDownEvents = listOf(