Skip to content

Commit

Permalink
Add support for Ctrl+U to delete line backwards (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximbaz authored Jul 11, 2023
1 parent ebb9b38 commit 1df2baa
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions src/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit 1df2baa

Please sign in to comment.