diff --git a/README.md b/README.md index 2a6325a..66a57a6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,5 @@ todo - When pressing enter, skip filled words - Shift-enter - check puzzle when grid is filled -- when pressing enter, jump to _first unfilled cell_ in next clue - fix bug with that one 6x6 puzzle - correctly calculate uiHeight with multi-line clues -- properly handle panics diff --git a/main.go b/main.go index fecb18e..e117eae 100644 --- a/main.go +++ b/main.go @@ -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() { if state.SelectedClue == nil { return @@ -158,7 +167,7 @@ func (state *State) NextWord() { if foundSelectedClue && clue.Direction == state.SelectedClue.Direction { state.SelectedClue = clue - state.SelectedCell = clue.Cells[0] + state.SelectedCell = state.FirstUnfilledCellForClue(clue) return } } @@ -166,7 +175,7 @@ func (state *State) NextWord() { for _, clue := range state.Puzzle.Clues { if clue.Direction != state.SelectedClue.Direction { state.SelectedClue = clue - state.SelectedCell = clue.Cells[0] + state.SelectedCell = state.FirstUnfilledCellForClue(clue) return } } @@ -223,6 +232,12 @@ func main() { 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, "") flag.Parse()