desktop: fixed shift+enter (#2842)

This commit is contained in:
Stanislav Dmitrenko
2023-08-03 14:04:26 +03:00
committed by GitHub
parent 8bf830ced9
commit b23b109b00

View File

@@ -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()) {