Enum tui_textarea::CursorMove
source · [−]pub enum CursorMove {
}Expand description
Specify how to move the cursor.
Variants
Forward
Move cursor forward by one character. When the cursor is at the end of line, it moves to the head of next line.
use tui_textarea::{TextArea, CursorMove};
let mut textarea = TextArea::from(["abc"]);
textarea.move_cursor(CursorMove::Forward);
assert_eq!(textarea.cursor(), (0, 1));
textarea.move_cursor(CursorMove::Forward);
assert_eq!(textarea.cursor(), (0, 2));Back
Move cursor backward by one character. When the cursor is at the head of line, it moves to the end of previous line.
use tui_textarea::{TextArea, CursorMove};
let mut textarea = TextArea::from(["abc"]);
textarea.move_cursor(CursorMove::Forward);
textarea.move_cursor(CursorMove::Forward);
textarea.move_cursor(CursorMove::Back);
assert_eq!(textarea.cursor(), (0, 1));Up
Move cursor up by one line.
use tui_textarea::{TextArea, CursorMove};
let mut textarea = TextArea::from(["a", "b", "c"]);
textarea.move_cursor(CursorMove::Down);
textarea.move_cursor(CursorMove::Down);
textarea.move_cursor(CursorMove::Up);
assert_eq!(textarea.cursor(), (1, 0));Down
Move cursor down by one line.
use tui_textarea::{TextArea, CursorMove};
let mut textarea = TextArea::from(["a", "b", "c"]);
textarea.move_cursor(CursorMove::Down);
assert_eq!(textarea.cursor(), (1, 0));
textarea.move_cursor(CursorMove::Down);
assert_eq!(textarea.cursor(), (2, 0));Head
Move cursor to the head of line. When the cursor is at the head of line, it moves to the end of previous line.
use tui_textarea::{TextArea, CursorMove};
let mut textarea = TextArea::from(["abc"]);
textarea.move_cursor(CursorMove::Forward);
textarea.move_cursor(CursorMove::Forward);
textarea.move_cursor(CursorMove::Head);
assert_eq!(textarea.cursor(), (0, 0));End
Move cursor to the end of line. When the cursor is at the end of line, it moves to the head of next line.
use tui_textarea::{TextArea, CursorMove};
let mut textarea = TextArea::from(["abc"]);
textarea.move_cursor(CursorMove::End);
assert_eq!(textarea.cursor(), (0, 3));Top
Move cursor to the top of lines.
use tui_textarea::{TextArea, CursorMove};
let mut textarea = TextArea::from(["a", "b", "c"]);
textarea.move_cursor(CursorMove::Down);
textarea.move_cursor(CursorMove::Down);
textarea.move_cursor(CursorMove::Top);
assert_eq!(textarea.cursor(), (0, 0));Bottom
Move cursor to the bottom of lines.
use tui_textarea::{TextArea, CursorMove};
let mut textarea = TextArea::from(["a", "b", "c"]);
textarea.move_cursor(CursorMove::Bottom);
assert_eq!(textarea.cursor(), (2, 0));WordForward
Move cursor forward by one word. Word boundary appears at spaces, punctuations, and others. For example
fn foo(a) consists of words fn, foo, (, a, ). When the cursor is at the end of line, it moves to the
head of next line.
use tui_textarea::{TextArea, CursorMove};
let mut textarea = TextArea::from(["aaa bbb ccc"]);
textarea.move_cursor(CursorMove::WordForward);
assert_eq!(textarea.cursor(), (0, 4));
textarea.move_cursor(CursorMove::WordForward);
assert_eq!(textarea.cursor(), (0, 8));WordBack
Move cursor backward by one word. Word boundary appears at spaces, punctuations, and others. For example
fn foo(a) consists of words fn, foo, (, a, ).When the cursor is at the head of line, it moves to
the end of previous line.
use tui_textarea::{TextArea, CursorMove};
let mut textarea = TextArea::from(["aaa bbb ccc"]);
textarea.move_cursor(CursorMove::End);
textarea.move_cursor(CursorMove::WordBack);
assert_eq!(textarea.cursor(), (0, 8));
textarea.move_cursor(CursorMove::WordBack);
assert_eq!(textarea.cursor(), (0, 4));
textarea.move_cursor(CursorMove::WordBack);
assert_eq!(textarea.cursor(), (0, 0));ParagraphForward
Move cursor down by one paragraph. Paragraph is a chunk of non-empty lines. Cursor moves to the first line of paragraph.
use tui_textarea::{TextArea, CursorMove};
// aaa
//
// bbb
//
// ccc
// ddd
let mut textarea = TextArea::from(["aaa", "", "bbb", "", "ccc", "ddd"]);
textarea.move_cursor(CursorMove::ParagraphForward);
assert_eq!(textarea.cursor(), (2, 0));
textarea.move_cursor(CursorMove::ParagraphForward);
assert_eq!(textarea.cursor(), (4, 0));ParagraphBack
Move cursor up by one paragraph. Paragraph is a chunk of non-empty lines. Cursor moves to the first line of paragraph.
use tui_textarea::{TextArea, CursorMove};
// aaa
//
// bbb
//
// ccc
// ddd
let mut textarea = TextArea::from(["aaa", "", "bbb", "", "ccc", "ddd"]);
textarea.move_cursor(CursorMove::Bottom);
textarea.move_cursor(CursorMove::ParagraphBack);
assert_eq!(textarea.cursor(), (4, 0));
textarea.move_cursor(CursorMove::ParagraphBack);
assert_eq!(textarea.cursor(), (2, 0));
textarea.move_cursor(CursorMove::ParagraphBack);
assert_eq!(textarea.cursor(), (0, 0));Jump(u16, u16)
Move cursor to (row, col) position. When the position points outside the text, the cursor position is made fit within the text. Note that row and col are 0-based. (0, 0) means the first character of the first line.
When there are 10 lines, jumping to row 15 moves the cursor to the last line (row is 9 in the case). When there are 10 characters in the line, jumping to col 15 moves the cursor to end of the line (col is 10 in the case).
use tui_textarea::{TextArea, CursorMove};
let mut textarea = TextArea::from(["aaaa", "bbbb", "cccc"]);
textarea.move_cursor(CursorMove::Jump(1, 2));
assert_eq!(textarea.cursor(), (1, 2));
textarea.move_cursor(CursorMove::Jump(10, 10));
assert_eq!(textarea.cursor(), (2, 4));Trait Implementations
sourceimpl Clone for CursorMove
impl Clone for CursorMove
sourcefn clone(&self) -> CursorMove
fn clone(&self) -> CursorMove
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for CursorMove
impl Debug for CursorMove
impl Copy for CursorMove
Auto Trait Implementations
impl RefUnwindSafe for CursorMove
impl Send for CursorMove
impl Sync for CursorMove
impl Unpin for CursorMove
impl UnwindSafe for CursorMove
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more