@@ -50,7 +50,6 @@ import androidx.compose.ui.text.font.FontWeight
5050import androidx.compose.ui.text.input.ImeAction
5151import androidx.compose.ui.text.input.KeyboardCapitalization
5252import androidx.compose.ui.text.input.TextFieldValue
53- import androidx.compose.ui.text.TextRange
5453import androidx.compose.ui.tooling.preview.Preview
5554import androidx.compose.ui.unit.dp
5655import androidx.hilt.navigation.compose.hiltViewModel
@@ -72,7 +71,7 @@ import to.bitkit.ui.utils.withAccent
7271import to.bitkit.viewmodels.RestoreWalletViewModel
7372
7473@Composable
75- fun RestoreWalletView (
74+ fun RestoreWalletScreen (
7675 viewModel : RestoreWalletViewModel = hiltViewModel(),
7776 onBackClick : () -> Unit ,
7877 onRestoreClick : (mnemonic: String , passphrase: String? ) -> Unit ,
@@ -337,13 +336,23 @@ fun MnemonicInputField(
337336 focusRequester : FocusRequester ,
338337 index : Int ,
339338) {
340- var isFocused by remember { mutableStateOf(false ) }
341- val textFieldValue = TextFieldValue (text = value, selection = TextRange (value.length))
339+ var textFieldValue by remember { mutableStateOf(TextFieldValue ()) }
340+
341+ // Sync text from parent while preserving selection
342+ LaunchedEffect (value) {
343+ if (textFieldValue.text != value) {
344+ val selection = textFieldValue.selection
345+ textFieldValue = TextFieldValue (value, selection)
346+ }
347+ }
342348
343349 OutlinedTextField (
344350 value = textFieldValue,
345- onValueChange = { onValueChanged(it.text) },
346- textStyle = if (isFocused) AppTextStyles .BodySSB else AppTextStyles .BodyS ,
351+ onValueChange = {
352+ textFieldValue = it
353+ onValueChanged(it.text)
354+ },
355+ textStyle = AppTextStyles .BodySSB ,
347356 prefix = {
348357 Text (
349358 text = label,
@@ -376,7 +385,6 @@ fun MnemonicInputField(
376385 }
377386 .testTag(" Word-$index " )
378387 .onFocusChanged { focusState ->
379- isFocused = focusState.isFocused
380388 onFocusChanged(focusState.isFocused)
381389 }
382390 .onGloballyPositioned { coordinates ->
@@ -390,7 +398,7 @@ fun MnemonicInputField(
390398@Composable
391399private fun Preview () {
392400 AppThemeSurface {
393- RestoreWalletView (
401+ RestoreWalletScreen (
394402 onBackClick = {},
395403 onRestoreClick = { _, _ -> },
396404 )
0 commit comments