From 83ff9b3345224ffb8706cf8a63186e74474338ca Mon Sep 17 00:00:00 2001 From: Helium314 Date: Wed, 11 Jun 2025 19:43:42 +0200 Subject: [PATCH] bring up keyboard when adding a new word in personal dictionary screen fixes GH-1663 --- .../settings/screens/PersonalDictionaryScreen.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/helium314/keyboard/settings/screens/PersonalDictionaryScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/PersonalDictionaryScreen.kt index 7c0d88b3e..7628827f2 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/PersonalDictionaryScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/PersonalDictionaryScreen.kt @@ -20,12 +20,15 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TextField import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource @@ -83,6 +86,11 @@ fun PersonalDictionaryScreen( ) if (selectedWord != null) { val selWord = selectedWord!! + val focusRequester = remember { FocusRequester() } + LaunchedEffect(selectedWord) { + if (selWord.word == "" && selWord.weight == null && selWord.shortcut == null) + focusRequester.requestFocus() // user clicked add word + } var newWord by remember { mutableStateOf(selWord) } var newLocale by remember { mutableStateOf(locale) } val wordValid = (newWord.word == selWord.word && locale == newLocale) || !doesWordExist(newWord.word, newLocale, ctx) @@ -119,7 +127,7 @@ fun PersonalDictionaryScreen( TextField( value = newWord.word, onValueChange = { newWord = newWord.copy(word = it) }, - modifier = Modifier.fillMaxWidth(), + modifier = Modifier.fillMaxWidth().focusRequester(focusRequester), singleLine = true ) Row(