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/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 128cab7..5454caf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -344,6 +344,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(); } 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.",