зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-03 14:26:17 +03:00
implement TextArea::select_all
but it is not assigned to default key shortcuts because C-a is already in use.
Этот коммит содержится в:
@@ -489,6 +489,7 @@ notify how to move the cursor.
|
||||
| `textarea.paste()` | Paste yanked text |
|
||||
| `textarea.start_selection()` | Start text selection |
|
||||
| `textarea.cancel_selection()` | Cancel text selection |
|
||||
| `textarea.select_all()` | Select entire text |
|
||||
| `textarea.move_cursor(CursorMove::Forward)` | Move cursor forward by one character |
|
||||
| `textarea.move_cursor(CursorMove::Back)` | Move cursor backward by one character |
|
||||
| `textarea.move_cursor(CursorMove::Up)` | Move cursor up by one line |
|
||||
|
||||
@@ -1312,6 +1312,26 @@ impl<'a> TextArea<'a> {
|
||||
self.selection_start = None;
|
||||
}
|
||||
|
||||
/// Select the entire text. Cursor moves to the end of the text buffer. When text selection is already ongoing,
|
||||
/// it is canceled.
|
||||
/// ```
|
||||
/// use tui_textarea::{TextArea, CursorMove};
|
||||
///
|
||||
/// let mut textarea = TextArea::from(["aaa", "bbb", "ccc"]);
|
||||
///
|
||||
/// textarea.select_all();
|
||||
///
|
||||
/// // Cut the entire text;
|
||||
/// textarea.cut();
|
||||
///
|
||||
/// assert_eq!(textarea.lines(), [""]); // Buffer is now empty
|
||||
/// assert_eq!(textarea.yank_text(), "aaa\nbbb\nccc");
|
||||
/// ```
|
||||
pub fn select_all(&mut self) {
|
||||
self.move_cursor(CursorMove::Jump(u16::MAX, u16::MAX));
|
||||
self.selection_start = Some((0, 0));
|
||||
}
|
||||
|
||||
/// Return if text selection is ongoing or not.
|
||||
/// ```
|
||||
/// use tui_textarea::{TextArea};
|
||||
|
||||
@@ -1420,6 +1420,18 @@ fn test_set_yank_paste_text() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_select_all() {
|
||||
let mut t = TextArea::from(["aaa", "bbb", "ccc"]);
|
||||
t.select_all();
|
||||
assert!(t.is_selecting());
|
||||
assert_eq!(t.cursor(), (2, 3));
|
||||
t.cut();
|
||||
assert_eq!(t.lines(), [""]);
|
||||
assert_eq!(t.yank_text(), "aaa\nbbb\nccc");
|
||||
assert_undo_redo((2, 3), &["aaa", "bbb", "ccc"], &[""], &mut t, "");
|
||||
}
|
||||
|
||||
struct DeleteTester(&'static [&'static str], fn(&mut TextArea) -> bool);
|
||||
impl DeleteTester {
|
||||
fn test(&self, before: (usize, usize), after: (usize, usize, &[&str], &str)) {
|
||||
|
||||
Ссылка в новой задаче
Block a user