Skip to content

Commit bdd30f1

Browse files
adding support for alt+ctrl+h to delete backward word
1 parent 8192cf1 commit bdd30f1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

codex-rs/tui/src/bottom_pane/textarea.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ impl TextArea {
231231
code: KeyCode::Enter,
232232
..
233233
} => self.insert_str("\n"),
234+
KeyEvent {
235+
code: KeyCode::Char('h'),
236+
modifiers,
237+
..
238+
} if modifiers == (KeyModifiers::CONTROL | KeyModifiers::ALT) => {
239+
self.delete_backward_word()
240+
},
234241
KeyEvent {
235242
code: KeyCode::Backspace,
236243
modifiers: KeyModifiers::ALT,
@@ -1171,6 +1178,30 @@ mod tests {
11711178
assert_eq!(t.cursor(), 2);
11721179
}
11731180

1181+
#[test]
1182+
fn delete_backward_word_alt_keys() {
1183+
use crossterm::event::KeyCode;
1184+
use crossterm::event::KeyEvent;
1185+
use crossterm::event::KeyModifiers;
1186+
1187+
// Test the custom Alt+Ctrl+h binding
1188+
let mut t = ta_with("hello world");
1189+
t.set_cursor(t.text().len()); // cursor at the end
1190+
t.input(KeyEvent::new(
1191+
KeyCode::Char('h'),
1192+
KeyModifiers::CONTROL | KeyModifiers::ALT,
1193+
));
1194+
assert_eq!(t.text(), "hello ");
1195+
assert_eq!(t.cursor(), 6);
1196+
1197+
// Test the standard Alt+Backspace binding
1198+
let mut t = ta_with("hello world");
1199+
t.set_cursor(t.text().len()); // cursor at the end
1200+
t.input(KeyEvent::new(KeyCode::Backspace, KeyModifiers::ALT));
1201+
assert_eq!(t.text(), "hello ");
1202+
assert_eq!(t.cursor(), 6);
1203+
}
1204+
11741205
#[test]
11751206
fn cursor_vertical_movement_across_lines_and_bounds() {
11761207
let mut t = ta_with("short\nloooooooooong\nmid");

0 commit comments

Comments
 (0)