feat(text_box): add CTRL+<backspace> and CTRL+<delete> keybinds (delete left/right word) (#353)

This commit is contained in:
ellieplayswow 2025-05-12 15:12:48 +01:00 committed by GitHub
parent 32cab6eef6
commit 40a54654dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -935,6 +935,19 @@ where
editor.action(Action::Motion(motion));
}
// Pre-select word for CTRL+<backspace> and CTRL+<delete>
fn delete_modifiers(
editor: &mut BorrowedWithFontSystem<'_, ViEditor<'static, 'static>>,
motion_to_apply: Motion,
modifiers: Modifiers,
) {
if modifiers.control() && editor.selection() == Selection::None {
let cursor = editor.cursor();
editor.set_selection(Selection::Normal(cursor));
editor.action(Action::Motion(motion_to_apply));
}
}
let mut status = Status::Ignored;
match event {
Event::Keyboard(KeyEvent::KeyPressed {
@ -983,10 +996,12 @@ where
status = Status::Captured;
}
Named::Backspace => {
delete_modifiers(&mut editor, Motion::LeftWord, modifiers);
editor.action(Action::Backspace);
status = Status::Captured;
}
Named::Delete => {
delete_modifiers(&mut editor, Motion::RightWord, modifiers);
editor.action(Action::Delete);
status = Status::Captured;
}