sudoku: keep the selection when the selected cell is tapped again (#ux-audit)
- Commit
e2c65cf40281fe0062b483a0edfa8cac08455129- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 01:09 UTC (23 days ago)
- Parents
e211669
Symptom: tapping the cell that is already selected cleared the selection. A player re-tapping a cell to confirm where they were, or a slightly bouncy double tap, lost the cursor, and the next number-pad press silently did nothing because no cell was selected. Root cause: SudokuViewModel.selectCell() toggled - it set selected to -1 when the tapped index matched the current selection. Fix: selectCell() now always selects the tapped cell. There is no user need for a "deselect" gesture: the win path still clears the selection itself, and tapping any other cell moves it as before. User-visible effect: tapping the selected cell keeps it selected and its row/column/box highlight stays on, so number-pad input always lands where the player is looking. Verification: SudokuViewModelTest's selection test now asserts that a second tap on the same cell keeps it selected (renamed to selectCellKeepsSelectionAndDigitPlacementEraseAndUndo); :games:sudoku:testDevUnitTest in the toolchain container.
Diff
games/sudoku/src/main/java/com/vayunmathur/games/sudoku/platform/SudokuViewModel.kt
diff --git a/games/sudoku/src/main/java/com/vayunmathur/games/sudoku/platform/SudokuViewModel.kt b/games/sudoku/src/main/java/com/vayunmathur/games/sudoku/platform/SudokuViewModel.ktindex fba2a42a72..953c559ede 100644--- a/games/sudoku/src/main/java/com/vayunmathur/games/sudoku/platform/SudokuViewModel.kt+++ b/games/sudoku/src/main/java/com/vayunmathur/games/sudoku/platform/SudokuViewModel.kt@@ -124,8 +124,15 @@ class SudokuViewModel(application: Application) : AndroidViewModel(application), } } + /**+ * Moves the cursor to [index].+ *+ * Re-tapping the selected cell keeps it selected. It used to toggle the selection off, so a+ * player double-checking a cell (or a slightly bouncy tap) lost their place and the next+ * number-pad press silently did nothing.+ */ override fun selectCell(index: Int) {- mutate { it.copy(selected = if (it.selected == index) -1 else index) }+ mutate { it.copy(selected = index) } } override fun toggleNotesMode() {
games/sudoku/src/test/java/com/vayunmathur/games/sudoku/platform/SudokuViewModelTest.kt
diff --git a/games/sudoku/src/test/java/com/vayunmathur/games/sudoku/platform/SudokuViewModelTest.kt b/games/sudoku/src/test/java/com/vayunmathur/games/sudoku/platform/SudokuViewModelTest.ktindex a68748d788..bc12b6fb36 100644--- a/games/sudoku/src/test/java/com/vayunmathur/games/sudoku/platform/SudokuViewModelTest.kt+++ b/games/sudoku/src/test/java/com/vayunmathur/games/sudoku/platform/SudokuViewModelTest.kt@@ -100,7 +100,7 @@ class SudokuViewModelTest { } @Test- fun selectCellTogglesAndDigitPlacementEraseAndUndo() {+ fun selectCellKeepsSelectionAndDigitPlacementEraseAndUndo() { val vm = startedVm() val cell = blank(vm) val game = vm.uiState.value.game!!@@ -109,8 +109,7 @@ class SudokuViewModelTest { vm.selectCell(cell) assertEquals(cell, vm.uiState.value.game!!.selected) vm.selectCell(cell)- assertEquals(-1, vm.uiState.value.game!!.selected, "re-selecting deselects")- vm.selectCell(cell)+ assertEquals(cell, vm.uiState.value.game!!.selected, "re-tapping keeps the selection") vm.enterDigit(correct) var after = vm.uiState.value.game!!