Skip to content

fix cli ui: ctrl+backspace does not delete word in windows terminals #21445

@dogukanozen

Description

@dogukanozen

bug:
In windows terminals, pressing ctrl+backspace is expected to delete the previous word. Howover this shortcut does not work in gemini clis input prompt, only deletes a single chracter instead of the entire previous word.

solution:
windows terminals sends the code \x08 (ASCII backspace same as CTRL + H) when ctrl+backspace is pressed. Currently /packages/cli/src/ui/contexts/KeypressContext.tsx line 595 treats this as a regular backspace and doesnt set the ctrl flag to true. :
else if (ch === '\b' || ch === '\x7f') {
// backspace or ctrl+h
name = 'backspace';
alt = escaped;
}

by splitting the handling of \b ( \x08 ascii) and \x7f, and explicitly setting ctrl: true for the \b case, the existing DELETE_WORD_BACWARD key binding ({ key: 'backspace', ctrl: true }) is correctly triggered. =>

else if (ch === '\b') {
// ctrl+h or ctrl+backspace (windows terminals send \x08 for ctrl+backspace)
name = 'backspace';
ctrl = true;
alt = escaped;
} else if (ch === '\x7f') {
// backspace
name = 'backspace';
alt = escaped;
}
so
ctrl+backspace => deletes the previous word (like windows terminal)
ctrl +h => also deletes the previous word.
regular backspace (\x7f) => remains unchanged and deletes a singe chracter.

btw, this is my first-ever open source contribution and pull request. be nice :P

Metadata

Metadata

Assignees

Labels

area/coreIssues related to User Interface, OS Support, Core Functionalityhelp wantedWe will accept PRs from all issues marked as "help wanted". Thanks for your support!status/possible-duplicate

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions