feat: add word-delete-keybindings#63
Conversation
There was a problem hiding this comment.
Pull request overview
Adds “delete previous word” behavior during an active typing test, wiring new keybindings in the TUI to game-level deletion logic (including a Termux-friendly mapping).
Changes:
- Added
(*game.Game).BackspaceWord()to delete the last word from the current input. - Updated typing key handling so
ctrl+wdeletes a word during an active test while preserving its existing pre-start behavior. - Updated
ctrl+hto act as word-delete while typing (for Termux’ctrl+backspacemapping) while keeping help behavior when not started.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| internal/tui/typing.go | Routes ctrl+w / ctrl+h to word-delete during active typing while preserving pre-start bindings. |
| internal/game/game.go | Implements word-level backspace logic that the TUI can call during a test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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 |
There was a problem hiding this comment.
ctrl + backspace would be a better choice
There was a problem hiding this comment.
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
| //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 | ||
| } |
There was a problem hiding this comment.
people use termux on mobile right?
There was a problem hiding this comment.
yeah, on mobile with aarch64 because it reads ^Backspace as ^h
| 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() | ||
| } |
|
wait... you just removed help keybind 😅 |
The ^H will only activate when there is an active test. The help keybind stays the same before starting the test hehe |
adds word-delete support while typing:
ctrl+w deletes the last word during an active test while preserving existing keybind.
if using termux, ctrl+h (ctrl + backspace in termux) also deletes the last word while typing.