From b23b109b00f9103d6f5d1696c5a9d50bde2e8817 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Thu, 3 Aug 2023 14:04:26 +0300 Subject: [PATCH] desktop: fixed shift+enter (#2842) --- .../common/platform/PlatformTextField.desktop.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/PlatformTextField.desktop.kt b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/PlatformTextField.desktop.kt index eef710711d..36feb1abdf 100644 --- a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/PlatformTextField.desktop.kt +++ b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/PlatformTextField.desktop.kt @@ -16,8 +16,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.input.key.* import androidx.compose.ui.platform.* -import androidx.compose.ui.text.TextRange -import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.* import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.text.input.TextFieldValue @@ -29,6 +28,7 @@ import chat.simplex.res.MR import dev.icerock.moko.resources.StringResource import kotlinx.coroutines.delay import kotlin.math.min +import kotlin.text.substring @Composable actual fun PlatformTextField( @@ -74,10 +74,12 @@ actual fun PlatformTextField( .onPreviewKeyEvent { if (it.key == Key.Enter && it.type == KeyEventType.KeyDown) { if (it.isShiftPressed) { - val newText = textFieldValue.text + "\n" + val start = if (minOf(textFieldValue.selection.min) == 0) "" else textFieldValue.text.substring(0 until textFieldValue.selection.min) + val newText = start + "\n" + + textFieldValue.text.substring(textFieldValue.selection.max, textFieldValue.text.length) textFieldValueState = textFieldValue.copy( text = newText, - selection = TextRange(newText.length, newText.length) + selection = TextRange(textFieldValue.selection.min + 1) ) onMessageChange(newText) } else if (cs.message.isNotEmpty()) {