Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Ctrl+U to delete line backwards #230

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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();
}
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