jump to unfilled cell + handle panics

This commit is contained in:
cjdenio committed 2026-09-02 21:32:46 -06:00
1 parent 9eba7080ea
commit 25e547e92a
2 files changed
+17 -4

No files matched your search

-2
View File
@@ -3,7 +3,5 @@ todo
- When pressing enter, skip filled words - When pressing enter, skip filled words
- Shift-enter - Shift-enter
- check puzzle when grid is filled - check puzzle when grid is filled
- when pressing enter, jump to _first unfilled cell_ in next clue
- fix bug with that one 6x6 puzzle - fix bug with that one 6x6 puzzle
- correctly calculate uiHeight with multi-line clues - correctly calculate uiHeight with multi-line clues
- properly handle panics
+17 -2
View File
@@ -143,6 +143,15 @@ func (state *State) MoveCursor(direction int) {
} }
} }
func (state *State) FirstUnfilledCellForClue(clue *puz.Clue) int {
for _, cell := range clue.Cells {
if state.PuzzleState[cell] == '-' {
return cell
}
}
return clue.Cells[0]
}
func (state *State) NextWord() { func (state *State) NextWord() {
if state.SelectedClue == nil { if state.SelectedClue == nil {
return return
@@ -158,7 +167,7 @@ func (state *State) NextWord() {
if foundSelectedClue && clue.Direction == state.SelectedClue.Direction { if foundSelectedClue && clue.Direction == state.SelectedClue.Direction {
state.SelectedClue = clue state.SelectedClue = clue
state.SelectedCell = clue.Cells[0] state.SelectedCell = state.FirstUnfilledCellForClue(clue)
return return
} }
} }
@@ -166,7 +175,7 @@ func (state *State) NextWord() {
for _, clue := range state.Puzzle.Clues { for _, clue := range state.Puzzle.Clues {
if clue.Direction != state.SelectedClue.Direction { if clue.Direction != state.SelectedClue.Direction {
state.SelectedClue = clue state.SelectedClue = clue
state.SelectedCell = clue.Cells[0] state.SelectedCell = state.FirstUnfilledCellForClue(clue)
return return
} }
} }
@@ -223,6 +232,12 @@ func main() {
defer term.Restore(int(os.Stdin.Fd()), termState) defer term.Restore(int(os.Stdin.Fd()), termState)
defer func() {
if r := recover(); r != nil {
fmt.Print("!!! PROGRAM CRASHED !!! Error:\r\n", r, "\r\n")
}
}()
debugMode := flag.Bool("debug", false, "") debugMode := flag.Bool("debug", false, "")
flag.Parse() flag.Parse()