Skip to content

feat(sudoku): digit-first input — arm a keypad digit, tap cells to place - #781

Merged
wei18 merged 1 commit into
mainfrom
worktree-impl-722
Jul 11, 2026
Merged

wei18 merged 1 commit into
mainfrom
worktree-impl-722

Conversation

@wei18

@wei18 wei18 commented Jul 11, 2026

Copy link
Copy Markdown
Owner

What

Sudoku digit-first input (#722, owner UX proposal; recorded default = implicit dual-mode, no settings toggle). Tapping a keypad digit with no cell selected arms it — the button renders .borderedProminent with an .isSelected a11y trait, every placed instance of the digit lights with the existing same-digit token, and consecutive taps on empty cells place it (pencil mode: toggles that digit's note) through the existing placeDigit/toggleNote paths, so mistake/error/undo/completion/persistence rules apply unchanged. Cell-first flow is untouched when a selection exists.

Invariant armedDigit != nil ⟺ selection == nil: enforced at two mutator sites (select() disarms unconditionally incl. arrow keys; armDigit() clears selection), asserted at construction and in the test seam (CR hardening), and armedDigit is never persisted (verified — no snapshot field).

  • GameViewModel+DigitFirst.swift: keypadDigit/tapCell dispatchers (VM owns mutation decisions, directly unit-tested)
  • DigitPadView: armed visual via existing styles; compact layout's remaining == 0 disable now applies only with a live selection so exhausted digits can still be armed for notes
  • BoardView+Highlighting: same-digit target = selected digit ?? armed digit (mutually exclusive)

Verification

  • GameViewModel|BoardView filtered batches: 63 tests / 12 suites pass (12 new VM tests + 1 new armed-state snapshot); existing snapshot baselines byte-identical (verified by both reviewers)
  • swift build clean; swiftlint --strict 0 violations
  • Dual code review APPROVE — fact-check traced cell-first regression surfaces (incl. the cell-tap sync→Task hop under rapid-tap interleavings), the invariant's full write-site inventory, completion-overlay interaction, and the disabled-gate change; given cells stay inert per a11y: given cells still announced as interactive buttons by VoiceOver (epic 9 follow-up) #473 (documented in the dispatcher)

Closes #722

🤖 Generated with Claude Code

Owner UX proposal #722 (recorded default: implicit dual-mode, no settings
toggle). Tapping a keypad digit with NO cell selected arms it: the button
renders prominent, every placed instance of that digit lights up with the
existing same-digit token, and consecutive taps on empty cells place it
(or toggle its pencil note in notes mode) through the existing placeDigit/
toggleNote paths — mistake counting, error surfacing, undo, completion and
persistence rules all apply unchanged. Selecting a cell first keeps
today's cell-first flow untouched.

Invariant: armedDigit != nil iff selection == nil, enforced at exactly two
mutator sites in GameViewModel (select() disarms unconditionally — arrow-
key selection included; armDigit() clears selection). Tapping a user-
filled cell while armed falls back to select-and-disarm; given cells stay
inert (no Button wrapper per #473), same as cell-first.

- keypadDigit/tapCell dispatchers live in a new GameViewModel+DigitFirst
  extension (VM owns mutation decisions; directly unit-testable)
- DigitPadView: armed digit renders .borderedProminent + .isSelected a11y
  trait (no new strings, no new theme tokens); the compact layout's
  remaining==0 disable now applies only when a selection exists, so an
  exhausted digit can still be armed for notes use
- BoardView+Highlighting: isSameDigit target = selected cell's digit ??
  armedDigit (mutually exclusive by invariant)

Tests: 12 new VM tests (arm/disarm, placement-stays-armed, filled-cell
fallback, selection/armed mutual exclusion, pencil composition, undo) +
1 armed-state iPhone snapshot (new suite file; BoardViewTests sits at the
file_length ceiling). Existing snapshot baselines byte-identical.

Verification: GameViewModel|BoardView filtered batches 63 tests / 12
suites pass (full-suite runs segfault locally on unmodified main, known);
swift build clean; swiftlint --strict 0 violations; new snapshot PNG
eyeballed (armed keypad prominent, board same-digit tint, no selection
tint).

Closes #722

Co-Authored-By: Claude Fable 5 <[email protected]>
@wei18
wei18 enabled auto-merge (squash) July 11, 2026 13:10
@wei18
wei18 merged commit 8469492 into main Jul 11, 2026
4 checks passed
@wei18
wei18 deleted the worktree-impl-722 branch July 11, 2026 13:10
wei18 added a commit that referenced this pull request Jul 11, 2026
…722) (#782)

Timeline log for the five-issue wave: cross-app coordinate a11y l10n
(#755/PR #776), Sudoku state-suffix l10n (#771/PR #777), the #716 premise
refutation + pencil-notes snapshot regression lock (PR #778), MS practice
personal bests via seed-derived ids (#705/PR #779), and Sudoku digit-first
input (#722/PR #781). Records the three pre-push review catches, the
seed-reuse design decision, and process notes (haiku numeric spot-checks,
reviewer send-report instruction, filtered-batch verification).

Co-authored-by: Claude Fable 5 <[email protected]>
wei18 added a commit that referenced this pull request Jul 13, 2026
…, exhausted+armed opacity (#790) (#799)

Re-audit 2026-07-13 found three MAJOR gaps in #781's digit-first input,
all in BoardView/DigitPadView/BoardCellView:

1. `handleKeyPress`'s digit branch called `placeDigit(_:)` directly
   (via the now-removed `placeOrToggle`), which no-ops with no
   selection — Mac keyboard users had no way to arm a digit at all.
   Routes through the extracted `dispatchKeyboardDigit(_:)`, which
   calls `viewModel.keypadDigit(_:)` — the same arm/place/pencil-note
   dispatch the pointer-driven digit pad already uses.

2. An armed digit changes an empty cell's tap semantics (select →
   place) with zero VoiceOver signal — the cell's label still read
   only "Empty". `BoardCellView` now appends a localized "will place
   N" hint while armed, and `BoardView` posts an
   `AccessibilityNotification.Announcement` on arm/disarm. Three new
   catalog keys ("will place %lld", "Digit %lld armed", "Digit
   unarmed") across all 7 locales.

3. An exhausted-but-armed keypad digit dimmed to 0.35 opacity while
   still rendering `.borderedProminent` — looked disabled while
   staying interactive (armed digits are valid for notes use even
   when fully placed). Extracted `digitButtonOpacity(remaining:
   isArmed:)` excludes armed digits from the dim.

`dispatchKeyboardDigit`, `accessibilityLabel` (BoardCellView), and
`armedAnnouncementMessage`/`digitButtonOpacity` were widened from
`private` specifically so the new tests exercise the REAL logic
(confirmed red on pre-fix code via `git stash` + `swift test`) rather
than a re-implementation that can't regress. SwiftUI's `KeyPress` has
no public initializer (confirmed against Apple's Accessibility/
SwiftUI sample code), so `handleKeyPress` itself stays untested;
`dispatchKeyboardDigit` is the closest testable seam.

Verification: `swift test --package-path Packages/SudokuKit` — 303
tests / 63 suites pass (12 new); `mise run lint:swift_strict` 0
violations on changed files; `mise run scan:l10n` passes (2 catalogs,
7 locales complete). Sudoku-only — Minesweeper/GameShellKit untouched.

Closes #790

Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(sudoku): digit-first input — select a number, then tap cells

1 participant