1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-08 00:15:50 +03:00

add Key::Copy, Key::Cut, Key::Paste support

Этот коммит содержится в:
rhysd
2023-11-15 01:29:44 +09:00
родитель 523a888f26
Коммит 8e3a432ecc
5 изменённых файлов: 22 добавлений и 5 удалений

Просмотреть файл

@@ -252,9 +252,9 @@ Default key mappings are as follows:
| `Alt+D`, `Alt+Delete` | Delete one word next to cursor | | `Alt+D`, `Alt+Delete` | Delete one word next to cursor |
| `Ctrl+U` | Undo | | `Ctrl+U` | Undo |
| `Ctrl+R` | Redo | | `Ctrl+R` | Redo |
| `Ctrl+C` | Copy selected text | | `Ctrl+C`, `Copy` | Copy selected text |
| `Ctrl+X` | Cut selected text | | `Ctrl+X`, `Cut` | Cut selected text |
| `Ctrl+Y` | Paste yanked text | | `Ctrl+Y`, `Paste` | Paste yanked text |
| `Ctrl+F`, `` | Move cursor forward by one character | | `Ctrl+F`, `` | Move cursor forward by one character |
| `Ctrl+B`, `` | Move cursor backward by one character | | `Ctrl+B`, `` | Move cursor backward by one character |
| `Ctrl+P`, `` | Move cursor up by one line | | `Ctrl+P`, `` | Move cursor up by one line |

Просмотреть файл

@@ -45,6 +45,12 @@ pub enum Key {
PageDown, PageDown,
/// Escape key /// Escape key
Esc, 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 /// Virtual key to scroll down by mouse
MouseScrollDown, MouseScrollDown,
/// Virtual key to scroll up by mouse /// Virtual key to scroll up by mouse

Просмотреть файл

@@ -34,6 +34,9 @@ impl From<KeyCode> for Key {
KeyCode::DownArrow => Key::Down, KeyCode::DownArrow => Key::Down,
KeyCode::Delete => Key::Delete, KeyCode::Delete => Key::Delete,
KeyCode::Function(x) => Key::F(x), KeyCode::Function(x) => Key::F(x),
KeyCode::Copy => Key::Copy,
KeyCode::Cut => Key::Cut,
KeyCode::Paste => Key::Paste,
_ => Key::Null, _ => Key::Null,
} }
} }

Просмотреть файл

@@ -558,19 +558,24 @@ impl<'a> TextArea<'a> {
ctrl: true, ctrl: true,
alt: false, alt: false,
.. ..
}
| Input {
key: Key::Paste, ..
} => self.paste(), } => self.paste(),
Input { Input {
key: Key::Char('x'), key: Key::Char('x'),
ctrl: true, ctrl: true,
alt: false, alt: false,
.. ..
} => self.cut(), }
| Input { key: Key::Cut, .. } => self.cut(),
Input { Input {
key: Key::Char('c'), key: Key::Char('c'),
ctrl: true, ctrl: true,
alt: false, alt: false,
.. ..
} => { }
| Input { key: Key::Copy, .. } => {
self.copy(); self.copy();
false false
} }

Просмотреть файл

@@ -47,6 +47,9 @@ fn test_input_all_combinations_sanity() {
Esc, Esc,
MouseScrollDown, MouseScrollDown,
MouseScrollUp, MouseScrollUp,
Copy,
Cut,
Paste,
] { ] {
push_all_modifiers_combination(&mut inputs, k); push_all_modifiers_combination(&mut inputs, k);
} }