-
Notifications
You must be signed in to change notification settings - Fork 5k
fix issue #2713: adding support for alt+ctrl+h to delete backward word #2717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix issue #2713: adding support for alt+ctrl+h to delete backward word #2717
Conversation
All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
modifiers, | ||
.. | ||
} if modifiers == (KeyModifiers::CONTROL | KeyModifiers::ALT) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modifiers, | |
.. | |
} if modifiers == (KeyModifiers::CONTROL | KeyModifiers::ALT) => { | |
modifiers: KeyModifiers::CONTROL | KeyModifiers::ALT, | |
.. | |
} => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nornagon-openai tried that.
compiler is not treating that as a bitwise OR, but as a pattern alternation operator (basically OR).
So, either ctrl+h, or alt+h can trigger it, which we don't want.
The match guard is a comparison to bitwise OR, so it works for us.
warning: unreachable pattern
--> tui/src/bottom_pane/textarea.rs:249:15
|
234 | / KeyEvent {
235 | | code: KeyCode::Char('h'),
236 | | modifiers: KeyModifiers::CONTROL | KeyModifiers::ALT,
237 | | ..
238 | | } => self.delete_backward_word(),
| |_____________- matches all the relevant values
...
249 | | KeyEvent {
| _______________^
250 | | code: KeyCode::Char('h'),
251 | | modifiers: KeyModifiers::CONTROL,
252 | | ..
253 | | } => self.delete_backward(1),
| |_____________^ no value can reach this
|
= note: `#[warn(unreachable_patterns)]` on by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added another test (ctrl_h_backspace) for simple CTRL+H to backspace conversion, both these tests are failing if I do modifiers: KeyModifiers::CONTROL | KeyModifiers::ALT,
using match's pattern matching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, makes sense. thanks for checking!
bdd30f1
to
f016d62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall happy w/ this change, just a couple of nits.
use crossterm::event::KeyCode; | ||
use crossterm::event::KeyEvent; | ||
use crossterm::event::KeyModifiers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these aren't required as they're already imported at the top level, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. removed.
I just copied from the test above :P
|
||
// Test Ctrl+H as backspace | ||
let mut t = ta_with("hello"); | ||
t.set_cursor(3); // cursor after 'l' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test would be better if the "l" wasn't repeated, maybe change the text to be "abcdef" instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. makes sense.
4dbb45f
to
d9b02fc
Compare
This pr addresses the fix for #2713
Changes:
Alt+Ctrl+H
→delete_backward_word()
delete_backward_word_alt_keys()
that verifies both:Alt+Backspace
binding continues to workAlt+Ctrl+H
binding works correctly for backward word deletionTesting:
The test ensures both key combinations produce identical behavior:
Backward Compatibility:
This change is backward compatible - existing
Alt+Backspace
functionality remains unchanged while adding support for the terminal-specificAlt+Ctrl+H
variant