зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-08 00:15:50 +03:00
add missing shortcuts and methods
Этот коммит содержится в:
@@ -31,20 +31,10 @@ impl CursorMove {
|
|||||||
|
|
||||||
match self {
|
match self {
|
||||||
Forward if col >= lines[row].chars().count() => {
|
Forward if col >= lines[row].chars().count() => {
|
||||||
if row + 1 < lines.len() {
|
(row + 1 < lines.len()).then(|| (row + 1, 0))
|
||||||
Some((row + 1, 0))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Forward => Some((row, col + 1)),
|
Forward => Some((row, col + 1)),
|
||||||
Back if col == 0 => {
|
Back if col == 0 => (row > 0).then(|| (row - 1, lines[row - 1].chars().count())),
|
||||||
if row > 0 {
|
|
||||||
Some((row - 1, lines[row - 1].chars().count()))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Back => Some((row, col - 1)),
|
Back => Some((row, col - 1)),
|
||||||
Up if row == 0 => None,
|
Up if row == 0 => None,
|
||||||
Up => Some((row - 1, fit_col(col, &lines[row - 1]))),
|
Up => Some((row - 1, fit_col(col, &lines[row - 1]))),
|
||||||
|
|||||||
@@ -140,4 +140,8 @@ impl History {
|
|||||||
edit.undo(lines);
|
edit.undo(lines);
|
||||||
Some(edit.cursor_before())
|
Some(edit.cursor_before())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn max_items(&self) -> usize {
|
||||||
|
self.max_items
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ impl<'a> TextArea<'a> {
|
|||||||
if lines.is_empty() {
|
if lines.is_empty() {
|
||||||
lines.push(String::new());
|
lines.push(String::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
lines,
|
lines,
|
||||||
block: None,
|
block: None,
|
||||||
@@ -245,6 +246,11 @@ impl<'a> TextArea<'a> {
|
|||||||
ctrl: false,
|
ctrl: false,
|
||||||
alt: true,
|
alt: true,
|
||||||
}
|
}
|
||||||
|
| Input {
|
||||||
|
key: Key::Down,
|
||||||
|
ctrl: true,
|
||||||
|
alt: false,
|
||||||
|
}
|
||||||
| Input {
|
| Input {
|
||||||
key: Key::PageDown, ..
|
key: Key::PageDown, ..
|
||||||
} => self.move_cursor(CursorMove::ParagraphForward),
|
} => self.move_cursor(CursorMove::ParagraphForward),
|
||||||
@@ -253,6 +259,11 @@ impl<'a> TextArea<'a> {
|
|||||||
ctrl: false,
|
ctrl: false,
|
||||||
alt: true,
|
alt: true,
|
||||||
}
|
}
|
||||||
|
| Input {
|
||||||
|
key: Key::Up,
|
||||||
|
ctrl: true,
|
||||||
|
alt: false,
|
||||||
|
}
|
||||||
| Input {
|
| Input {
|
||||||
key: Key::PageUp, ..
|
key: Key::PageUp, ..
|
||||||
} => self.move_cursor(CursorMove::ParagraphBack),
|
} => self.move_cursor(CursorMove::ParagraphBack),
|
||||||
@@ -347,10 +358,10 @@ impl<'a> TextArea<'a> {
|
|||||||
|
|
||||||
let (row, col) = self.cursor;
|
let (row, col) = self.cursor;
|
||||||
let line = &mut self.lines[row];
|
let line = &mut self.lines[row];
|
||||||
debug_assert_eq!(
|
debug_assert!(
|
||||||
line.char_indices().find(|(_, c)| *c == '\n'),
|
!line.contains('\n'),
|
||||||
None,
|
"string given to insert_str must not contain newline: {:?}",
|
||||||
"string given to insert_str must not contain newline",
|
line,
|
||||||
);
|
);
|
||||||
|
|
||||||
let i = line
|
let i = line
|
||||||
@@ -557,6 +568,10 @@ impl<'a> TextArea<'a> {
|
|||||||
self.style = style;
|
self.style = style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn style(&self) -> Style {
|
||||||
|
self.style
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_block(&mut self, block: Block<'a>) {
|
pub fn set_block(&mut self, block: Block<'a>) {
|
||||||
self.block = Some(block);
|
self.block = Some(block);
|
||||||
}
|
}
|
||||||
@@ -565,18 +580,34 @@ impl<'a> TextArea<'a> {
|
|||||||
self.block = None;
|
self.block = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn block<'s>(&'s self) -> Option<&'s Block<'a>> {
|
||||||
|
self.block.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_tab_length(&mut self, len: u8) {
|
pub fn set_tab_length(&mut self, len: u8) {
|
||||||
self.tab_len = len;
|
self.tab_len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn tab_length(&self) -> u8 {
|
||||||
|
self.tab_len
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_max_histories(&mut self, max: usize) {
|
pub fn set_max_histories(&mut self, max: usize) {
|
||||||
self.history = History::new(max);
|
self.history = History::new(max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn max_histories(&self) -> usize {
|
||||||
|
self.history.max_items()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_cursor_line_style(&mut self, style: Style) {
|
pub fn set_cursor_line_style(&mut self, style: Style) {
|
||||||
self.cursor_line_style = style;
|
self.cursor_line_style = style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cursor_line_style(&self) -> Style {
|
||||||
|
self.cursor_line_style
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_line_number_style(&mut self, style: Style) {
|
pub fn set_line_number_style(&mut self, style: Style) {
|
||||||
self.line_number_style = Some(style);
|
self.line_number_style = Some(style);
|
||||||
}
|
}
|
||||||
@@ -585,10 +616,18 @@ impl<'a> TextArea<'a> {
|
|||||||
self.line_number_style = None;
|
self.line_number_style = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn line_number_style(&self) -> Option<Style> {
|
||||||
|
self.line_number_style
|
||||||
|
}
|
||||||
|
|
||||||
pub fn lines(&'a self) -> &'a [String] {
|
pub fn lines(&'a self) -> &'a [String] {
|
||||||
&self.lines
|
&self.lines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_lines(self) -> Vec<String> {
|
||||||
|
self.lines
|
||||||
|
}
|
||||||
|
|
||||||
/// 0-base character-wise (row, col) cursor position.
|
/// 0-base character-wise (row, col) cursor position.
|
||||||
pub fn cursor(&self) -> (usize, usize) {
|
pub fn cursor(&self) -> (usize, usize) {
|
||||||
self.cursor
|
self.cursor
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user