Skip to content

Commit 42ee9d2

Browse files
authored
feat: add enter key support for line progression (#9)
2 parents c19b4c1 + 9ef96c2 commit 42ee9d2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

internal/game/typing.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,27 @@ func (g *TypingGame) AddCharacter(char rune) {
149149
}
150150
}
151151

152+
// HandleEnterKey handles Enter key press for line progression
153+
func (g *TypingGame) HandleEnterKey() bool {
154+
if g.IsFinished || g.IsTimeUp() {
155+
return false
156+
}
157+
158+
lineText := []rune(g.DisplayLines[0])
159+
160+
// Only allow Enter to progress if at end of line
161+
if g.CurrentPos == len(lineText) {
162+
// Treat Enter like Space internally for consistency
163+
g.UserInput += " "
164+
g.CurrentPos++
165+
g.GlobalPos++
166+
g.shiftLines()
167+
return true
168+
}
169+
170+
return false
171+
}
172+
152173
// shiftLines moves to the next line in the game, updating the words typed and generating new lines
153174
func (g *TypingGame) shiftLines() {
154175
// Move to next line

internal/tui/update.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
2424
m.restartTest()
2525
return m, tickCmd()
2626
}
27+
// Handle Enter for line progression
28+
if m.game.HandleEnterKey() {
29+
return m, nil
30+
}
2731
return m, nil
2832

2933
case " ":

0 commit comments

Comments
 (0)