From e40ef3d3048554105bcbcb50f748a4103e1300ba Mon Sep 17 00:00:00 2001 From: Ryan Mitchener Date: Mon, 21 Feb 2022 10:50:21 -0500 Subject: [PATCH] Added KeyEventType check for keyboard events tutorial (#1877) Added KeyEventType check for keyboard events tutorial in response to https://github.com/JetBrains/compose-jb/issues/1871 --- tutorials/Keyboard/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tutorials/Keyboard/README.md b/tutorials/Keyboard/README.md index 94eff905dd..2f7f132f59 100644 --- a/tutorials/Keyboard/README.md +++ b/tutorials/Keyboard/README.md @@ -38,6 +38,8 @@ import androidx.compose.ui.input.key.Key import androidx.compose.ui.input.key.isCtrlPressed import androidx.compose.ui.input.key.key import androidx.compose.ui.input.key.onPreviewKeyEvent +import androidx.compose.ui.input.key.type +import androidx.compose.ui.input.key.KeyEventType import androidx.compose.ui.unit.dp import androidx.compose.ui.window.singleWindowApplication @@ -53,12 +55,12 @@ fun main() = singleWindowApplication { onValueChange = { text = it }, modifier = Modifier.onPreviewKeyEvent { when { - (it.isCtrlPressed && it.key == Key.Minus) -> { + (it.isCtrlPressed && it.key == Key.Minus && it.type == KeyEventType.KeyUp) -> { consumedText -= text.length text = "" true } - (it.isCtrlPressed && it.key == Key.Equals) -> { + (it.isCtrlPressed && it.key == Key.Equals && it.type == KeyEventType.KeyUp) -> { consumedText += text.length text = "" true