From 1a76ec5f5aaf1db2189c776b9dfa3bbd2e5c9e73 Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Mon, 10 Jul 2023 13:18:44 +0200 Subject: [PATCH 1/2] Add support for Ctrl+U to delete line backwards --- src/cursor.rs | 4 ++++ src/input.rs | 4 ++++ src/main.rs | 3 +++ 3 files changed, 11 insertions(+) diff --git a/src/cursor.rs b/src/cursor.rs index 3972f1a..6fea3f7 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -124,6 +124,10 @@ impl Cursor { } } + pub fn delete_line_backward(&mut self, text: &mut String) { + (0..self.col.max(1)).for_each(|_| self.delete_backward(text)) + } + pub fn delete_word_backward(&mut self, text: &mut String) { let end = self.idx; self.move_word_left(text); diff --git a/src/input.rs b/src/input.rs index 9e5074d..5677637 100644 --- a/src/input.rs +++ b/src/input.rs @@ -54,6 +54,10 @@ impl Input { self.cursor.delete_backward(&mut self.data); } + pub fn on_delete_line(&mut self) { + self.cursor.delete_line_backward(&mut self.data); + } + pub fn on_delete_word(&mut self) { self.cursor.delete_word_backward(&mut self.data); } diff --git a/src/main.rs b/src/main.rs index 0e64fcc..0f23f09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -342,6 +342,9 @@ async fn run_single_threaded(relink: bool) -> anyhow::Result<()> { KeyCode::Char('b') if event.modifiers.contains(KeyModifiers::ALT) => { app.get_input().move_back_word(); } + KeyCode::Char('u') if event.modifiers.contains(KeyModifiers::CONTROL) => { + app.get_input().on_delete_line(); + } KeyCode::Char('w') if event.modifiers.contains(KeyModifiers::CONTROL) => { app.get_input().on_delete_word(); } From 602166d0caf235357f40565a7f323e6fe76c2949 Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Tue, 11 Jul 2023 00:41:05 +0200 Subject: [PATCH 2/2] Document `ctrl+u` --- README.md | 1 + src/shortcuts.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/README.md b/README.md index 8d46396..6422e59 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ libraries that are not available on crates.io. * `alt+enter` Switch between multi-line and singl-line input modes. * `alt+left`, `alt+right` Jump to previous/next word. * `ctrl+w / ctrl+backspace / alt+backspace` Delete last word. + * `ctrl+u` Delete to the start of the line. * `enter` *when input box empty in single-line mode* Open URL from selected message. * `enter` *otherwise* Send message. * Multi-line message input diff --git a/src/shortcuts.rs b/src/shortcuts.rs index 638dbbd..a4c723e 100644 --- a/src/shortcuts.rs +++ b/src/shortcuts.rs @@ -26,6 +26,10 @@ pub static SHORTCUTS: &[ShortCut] = &[ event: "ctrl+w / ctrl+backspace / alt+backspace", description: "Delete last word.", }, + ShortCut { + event: "ctrl+u", + description: "Delete to the start of the line.", + }, ShortCut { event: "enter, when input box empty in single-line mode", description: "Open URL from selected message.",