зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-07 16:05:50 +03:00
new WordEnd enum member for CursorMove
Этот коммит содержится в:
@@ -1,5 +1,5 @@
|
|||||||
use crate::widget::Viewport;
|
use crate::widget::Viewport;
|
||||||
use crate::word::{find_word_start_backward, find_word_start_forward};
|
use crate::word::{find_word_end_next, find_word_start_backward, find_word_start_forward};
|
||||||
#[cfg(feature = "arbitrary")]
|
#[cfg(feature = "arbitrary")]
|
||||||
use arbitrary::Arbitrary;
|
use arbitrary::Arbitrary;
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
@@ -121,6 +121,29 @@ pub enum CursorMove {
|
|||||||
/// assert_eq!(textarea.cursor(), (0, 8));
|
/// assert_eq!(textarea.cursor(), (0, 8));
|
||||||
/// ```
|
/// ```
|
||||||
WordForward,
|
WordForward,
|
||||||
|
/// Move cursor forward to the next end of 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
|
||||||
|
/// end of the first word of the next line.
|
||||||
|
/// ```
|
||||||
|
/// use tui_textarea::{TextArea, CursorMove};
|
||||||
|
///
|
||||||
|
/// let mut textarea = TextArea::from(["aaa bbb (c)", " dd"]);
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// textarea.move_cursor(CursorMove::WordEnd);
|
||||||
|
/// assert_eq!(textarea.cursor(), (0, 2));
|
||||||
|
/// textarea.move_cursor(CursorMove::WordEnd);
|
||||||
|
/// assert_eq!(textarea.cursor(), (0, 6));
|
||||||
|
/// textarea.move_cursor(CursorMove::WordEnd);
|
||||||
|
/// assert_eq!(textarea.cursor(), (0, 8));
|
||||||
|
/// textarea.move_cursor(CursorMove::WordEnd);
|
||||||
|
/// assert_eq!(textarea.cursor(), (0, 9));
|
||||||
|
/// textarea.move_cursor(CursorMove::WordEnd);
|
||||||
|
/// assert_eq!(textarea.cursor(), (0, 10));
|
||||||
|
/// textarea.move_cursor(CursorMove::WordEnd);
|
||||||
|
/// assert_eq!(textarea.cursor(), (1, 2));
|
||||||
|
/// ```
|
||||||
|
WordEnd,
|
||||||
/// Move cursor backward by one word. Word boundary appears at spaces, punctuations, and others. For example
|
/// 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
|
/// `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.
|
/// the end of previous line.
|
||||||
@@ -263,6 +286,19 @@ impl CursorMove {
|
|||||||
let row = lines.len() - 1;
|
let row = lines.len() - 1;
|
||||||
Some((row, fit_col(col, &lines[row])))
|
Some((row, fit_col(col, &lines[row])))
|
||||||
}
|
}
|
||||||
|
WordEnd => {
|
||||||
|
if let Some(col) = find_word_end_next(&lines[row], col) {
|
||||||
|
Some((row, col))
|
||||||
|
} else if row + 1 < lines.len() {
|
||||||
|
if let Some(col) = find_word_end_next(&lines[row + 1], 0) {
|
||||||
|
Some((row + 1, col))
|
||||||
|
} else {
|
||||||
|
Some((row + 1, lines[row + 1].chars().count()))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Some((row, lines[row].chars().count()))
|
||||||
|
}
|
||||||
|
}
|
||||||
WordForward => {
|
WordForward => {
|
||||||
if let Some(col) = find_word_start_forward(&lines[row], col) {
|
if let Some(col) = find_word_start_forward(&lines[row], col) {
|
||||||
Some((row, col))
|
Some((row, col))
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user