Skip to content

Commit

Permalink
add Key::Copy, Key::Cut, Key::Paste support
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Nov 14, 2023
1 parent 523a888 commit 8e3a432
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ Default key mappings are as follows:
| `Alt+D`, `Alt+Delete` | Delete one word next to cursor |
| `Ctrl+U` | Undo |
| `Ctrl+R` | Redo |
| `Ctrl+C` | Copy selected text |
| `Ctrl+X` | Cut selected text |
| `Ctrl+Y` | Paste yanked text |
| `Ctrl+C`, `Copy` | Copy selected text |
| `Ctrl+X`, `Cut` | Cut selected text |
| `Ctrl+Y`, `Paste` | Paste yanked text |
| `Ctrl+F`, `` | Move cursor forward by one character |
| `Ctrl+B`, `` | Move cursor backward by one character |
| `Ctrl+P`, `` | Move cursor up by one line |
Expand Down
6 changes: 6 additions & 0 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ pub enum Key {
PageDown,
/// Escape key
Esc,
/// Copy key. This key is supported by termwiz only
Copy,
/// Cut key. This key is supported by termwiz only
Cut,
/// Paste key. This key is supported by termwiz only
Paste,
/// Virtual key to scroll down by mouse
MouseScrollDown,
/// Virtual key to scroll up by mouse
Expand Down
3 changes: 3 additions & 0 deletions src/input/termwiz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ impl From<KeyCode> for Key {
KeyCode::DownArrow => Key::Down,
KeyCode::Delete => Key::Delete,
KeyCode::Function(x) => Key::F(x),
KeyCode::Copy => Key::Copy,
KeyCode::Cut => Key::Cut,
KeyCode::Paste => Key::Paste,
_ => Key::Null,
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/textarea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,19 +558,24 @@ impl<'a> TextArea<'a> {
ctrl: true,
alt: false,
..
}
| Input {
key: Key::Paste, ..
} => self.paste(),
Input {
key: Key::Char('x'),
ctrl: true,
alt: false,
..
} => self.cut(),
}
| Input { key: Key::Cut, .. } => self.cut(),
Input {
key: Key::Char('c'),
ctrl: true,
alt: false,
..
} => {
}
| Input { key: Key::Copy, .. } => {
self.copy();
false
}
Expand Down
3 changes: 3 additions & 0 deletions tests/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ fn test_input_all_combinations_sanity() {
Esc,
MouseScrollDown,
MouseScrollUp,
Copy,
Cut,
Paste,
] {
push_all_modifiers_combination(&mut inputs, k);
}
Expand Down

0 comments on commit 8e3a432

Please sign in to comment.