commit dd5f799414c81547f8174c96d38f4ed29fbb3044
parent b0e611a44812a470ca68aaed7d0147c7de2085a0
Author: Michael Camilleri <[email protected]>
Date: Wed, 22 Apr 2026 04:02:40 +0900
Fix auto-advancing
Prior to this commit, when a user entered the last letter in a word, the
cursor would advance in the same direction. When advancing through
vertical clues, this resulted in the user advancing to the next word in
the column. However, the expectation is that the cursor would move to
the next sequential clue. This commit does that.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
Diffstat:
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/Crossmate/Models/PlayerSession.swift b/Crossmate/Models/PlayerSession.swift
@@ -270,18 +270,30 @@ final class PlayerSession {
private func advance() {
let (dr, dc) = step(for: direction)
- var r = selectedRow + dr
- var c = selectedCol + dc
- while isValid(row: r, col: c) && puzzle.cells[r][c].isBlock {
- r += dr
- c += dc
- }
- if isValid(row: r, col: c) {
+ let r = selectedRow + dr
+ let c = selectedCol + dc
+ // If we're still inside the current word, step one cell. Otherwise
+ // we've hit the end of the word, so jump to the next clue in the same
+ // direction by number. Without that, we'd fall through the block into
+ // a different word in the same row/column — which for down clues is
+ // almost never the next clue by number.
+ if isValid(row: r, col: c) && !puzzle.cells[r][c].isBlock {
selectedRow = r
selectedCol = c
+ } else {
+ advanceToNextClue()
}
}
+ private func advanceToNextClue() {
+ let clues = direction == .across ? puzzle.acrossClues : puzzle.downClues
+ guard !clues.isEmpty else { return }
+ let currentNumber = currentClueNumber()
+ let currentIndex = clues.firstIndex { $0.number == currentNumber } ?? -1
+ let nextIndex = (currentIndex + 1) % clues.count
+ moveToClueStart(number: clues[nextIndex].number)
+ }
+
private func retreat() {
let (dr, dc) = step(for: direction)
var r = selectedRow - dr