bring up keyboard when adding a new word in personal dictionary screen

fixes GH-1663
This commit is contained in:
Helium314 2025-06-11 19:43:42 +02:00
parent 8ae241b032
commit 83ff9b3345

View file

@ -20,12 +20,15 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextField import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier 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.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@ -83,6 +86,11 @@ fun PersonalDictionaryScreen(
) )
if (selectedWord != null) { if (selectedWord != null) {
val selWord = selectedWord!! 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 newWord by remember { mutableStateOf(selWord) }
var newLocale by remember { mutableStateOf(locale) } var newLocale by remember { mutableStateOf(locale) }
val wordValid = (newWord.word == selWord.word && locale == newLocale) || !doesWordExist(newWord.word, newLocale, ctx) val wordValid = (newWord.word == selWord.word && locale == newLocale) || !doesWordExist(newWord.word, newLocale, ctx)
@ -119,7 +127,7 @@ fun PersonalDictionaryScreen(
TextField( TextField(
value = newWord.word, value = newWord.word,
onValueChange = { newWord = newWord.copy(word = it) }, onValueChange = { newWord = newWord.copy(word = it) },
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth().focusRequester(focusRequester),
singleLine = true singleLine = true
) )
Row( Row(