Fix keyboard control

- restart has now focus after
  solving puzzle
- removed options can be added again
- removing a selection by keypress
  makes a rollback as well
This commit is contained in:
Christian Basler
2026-01-09 19:51:29 +01:00
parent c6f7cbae2b
commit b05099da46
2 changed files with 17 additions and 2 deletions

View File

@@ -13,10 +13,14 @@ import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.BlurEffect
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.testTag
@@ -36,6 +40,12 @@ fun EndOfGame(
time: String,
onRestart: () -> Unit
) {
val focusRequester = remember { FocusRequester() }
LaunchedEffect(isSolved) {
if (isSolved) {
focusRequester.requestFocus()
}
}
AnimatedVisibility(
visible = isSolved,
modifier = modifier,
@@ -72,6 +82,7 @@ fun EndOfGame(
Spacer(modifier = Modifier.height(32.dp))
Button(
modifier = Modifier.align(CenterHorizontally)
.focusRequester(focusRequester)
.testTag("EndOfGame.restart"),
onClick = onRestart
) {

View File

@@ -81,7 +81,7 @@ private fun PuzzleRow(
if (selection != null) {
when (e.key) {
Key.Spacebar, Key.Enter, Key.Delete, Key.Backspace -> {
selection = null
onSelectItem(row, cell, options, null, onSnapshot, onUndo)
true
}
@@ -92,7 +92,11 @@ private fun PuzzleRow(
if (i != null && i in 1..options.size) {
val selectedItem = options[i - 1].item
if (e.isShiftPressed) {
onOptionRemoved(row, cell, selectedItem, onSnapshot)
if (cell.options.contains(selectedItem)) {
onOptionRemoved(row, cell, selectedItem, onSnapshot)
} else {
cell.options.add(selectedItem)
}
} else {
onSelectItem(row, cell, options, selectedItem, onSnapshot, onUndo)
}