Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions internal/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,29 @@ func (g *Game) Backspace() {
}
g.recordRacePoint()
}
func (g *Game) BackspaceWord() {
if len(g.input) == 0 {
return
}

g.lastTyped = time.Now()

// Trim trailing spaces first
for len(g.input) > 0 && g.input[len(g.input)-1] == ' ' {
pos := len(g.input) - 1
g.input = g.input[:pos]
delete(g.errors, pos)
}

// Then delete until hitting a space or the beginning
for len(g.input) > 0 && g.input[len(g.input)-1] != ' ' {
pos := len(g.input) - 1
g.input = g.input[:pos]
delete(g.errors, pos)
}

g.recordRacePoint()
}
Comment on lines +181 to +203
func (g *Game) TimeLeft() int {
if !g.started {
return g.duration
Expand Down
16 changes: 11 additions & 5 deletions internal/tui/typing.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func (m model) handleTyping(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
}
m.game = game.New(m.duration, m.mode, m.lang, m.difficulty)
m.save()
} else {
m.game.BackspaceWord() //added ctrl + w to delete a whole word only when typing begins

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctrl + backspace would be a better choice

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yah, perhaps there's a way to auto-detect the architecture without forking any subprocesses? so when it detects non-aarch64, it will default to ^Backspace? I added the ^W since on most terminals, it deletes a whole word

}

case "ctrl+l":
Expand All @@ -67,6 +69,14 @@ func (m model) handleTyping(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
}
}

//this is for termux since it reads ctrl + backspace as ctrl + h
case "ctrl+h":
if m.game.Started() {
m.game.BackspaceWord()
} else {
m.showHelp = true
return m, nil
}
Comment on lines +72 to +79

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

people use termux on mobile right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, on mobile with aarch64 because it reads ^Backspace as ^h

case "ctrl+o":
if m.mode == "code" && !m.game.Started() {
m.activeRace = nil
Expand All @@ -83,11 +93,7 @@ func (m model) handleTyping(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
}
}

case "ctrl+h":
if !m.game.Started() {
m.showHelp = true
return m, nil
}


case "?":
if !m.game.Started() {
Expand Down