From 468611de705b6a1a0de7157bf6481eb748b2bb91 Mon Sep 17 00:00:00 2001 From: sebashwa Date: Mon, 23 May 2022 11:11:15 +0200 Subject: [PATCH] Implement for char deletion under cursor In inputs --- src/components/utils/input.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/components/utils/input.rs b/src/components/utils/input.rs index 974dd78..5f6dd29 100644 --- a/src/components/utils/input.rs +++ b/src/components/utils/input.rs @@ -153,6 +153,14 @@ impl Input { self.delete_right_until(index); return (Some(key), true); } + Key::Ctrl('d') => { + if self.cannot_go_right() { + return (Some(key), false); + } + + self.delete_right_until(self.cursor_index + 1); + return (Some(key), true); + } Key::Left | Key::Ctrl('b') => { if self.cannot_go_left() { return (Some(key), false); @@ -347,6 +355,20 @@ mod test { assert_eq!(input.cursor_index, 1); } + #[test] + fn test_deletes_char_under_current_cursor_for_ctrl_d() { + let mut input = Input::new(); + input.value = vec!['a', 'b', 'c', 'd']; + input.cursor_index = 1; + input.cursor_position = input.value_width(); + + let (matched_key, input_changed) = input.handle_key(Key::Ctrl('d')); + + assert_eq!(matched_key, Some(Key::Ctrl('d'))); + assert_eq!(input_changed, true); + assert_eq!(input.value, vec!['a', 'c', 'd']); + assert_eq!(input.cursor_index, 1); + } #[test] fn test_moves_backwards_til_nonalphanumeric_for_alt_b() { let mut input = Input::new();