1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-03 14:26:17 +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 |
| `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 |

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

@@ -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

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

@@ -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,
}
}

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

@@ -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
}

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

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