diff --git a/README.md b/README.md index f6a42fc..0a21d2f 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/src/input/mod.rs b/src/input/mod.rs index 1eb224e..2ead41b 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -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 diff --git a/src/input/termwiz.rs b/src/input/termwiz.rs index 562bd90..d88e53a 100644 --- a/src/input/termwiz.rs +++ b/src/input/termwiz.rs @@ -34,6 +34,9 @@ impl From 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, } } diff --git a/src/textarea.rs b/src/textarea.rs index bfb65d9..0f260a9 100644 --- a/src/textarea.rs +++ b/src/textarea.rs @@ -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 } diff --git a/tests/input.rs b/tests/input.rs index 836c84f..4dafeb0 100644 --- a/tests/input.rs +++ b/tests/input.rs @@ -47,6 +47,9 @@ fn test_input_all_combinations_sanity() { Esc, MouseScrollDown, MouseScrollUp, + Copy, + Cut, + Paste, ] { push_all_modifiers_combination(&mut inputs, k); }