From 40a54654dce89af14e9f2f403b30076b3187525f Mon Sep 17 00:00:00 2001 From: ellieplayswow <164806095+ellieplayswow@users.noreply.github.com> Date: Mon, 12 May 2025 15:12:48 +0100 Subject: [PATCH] feat(text_box): add CTRL+ and CTRL+ keybinds (delete left/right word) (#353) --- src/text_box.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/text_box.rs b/src/text_box.rs index c6a599f..19aaad9 100644 --- a/src/text_box.rs +++ b/src/text_box.rs @@ -935,6 +935,19 @@ where editor.action(Action::Motion(motion)); } + // Pre-select word for CTRL+ and CTRL+ + 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; }