1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-03 22:35:50 +03:00

add missing shortcuts and methods

Этот коммит содержится в:
rhysd
2022-06-12 15:17:40 +09:00
родитель 8d754dd53d
Коммит 03fcccc34a
3 изменённых файлов: 49 добавлений и 16 удалений

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

@@ -31,20 +31,10 @@ impl CursorMove {
match self {
Forward if col >= lines[row].chars().count() => {
if row + 1 < lines.len() {
Some((row + 1, 0))
} else {
None
}
(row + 1 < lines.len()).then(|| (row + 1, 0))
}
Forward => Some((row, col + 1)),
Back if col == 0 => {
if row > 0 {
Some((row - 1, lines[row - 1].chars().count()))
} else {
None
}
}
Back if col == 0 => (row > 0).then(|| (row - 1, lines[row - 1].chars().count())),
Back => Some((row, col - 1)),
Up if row == 0 => None,
Up => Some((row - 1, fit_col(col, &lines[row - 1]))),

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

@@ -140,4 +140,8 @@ impl History {
edit.undo(lines);
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() {
lines.push(String::new());
}
Self {
lines,
block: None,
@@ -245,6 +246,11 @@ impl<'a> TextArea<'a> {
ctrl: false,
alt: true,
}
| Input {
key: Key::Down,
ctrl: true,
alt: false,
}
| Input {
key: Key::PageDown, ..
} => self.move_cursor(CursorMove::ParagraphForward),
@@ -253,6 +259,11 @@ impl<'a> TextArea<'a> {
ctrl: false,
alt: true,
}
| Input {
key: Key::Up,
ctrl: true,
alt: false,
}
| Input {
key: Key::PageUp, ..
} => self.move_cursor(CursorMove::ParagraphBack),
@@ -347,10 +358,10 @@ impl<'a> TextArea<'a> {
let (row, col) = self.cursor;
let line = &mut self.lines[row];
debug_assert_eq!(
line.char_indices().find(|(_, c)| *c == '\n'),
None,
"string given to insert_str must not contain newline",
debug_assert!(
!line.contains('\n'),
"string given to insert_str must not contain newline: {:?}",
line,
);
let i = line
@@ -557,6 +568,10 @@ impl<'a> TextArea<'a> {
self.style = style;
}
pub fn style(&self) -> Style {
self.style
}
pub fn set_block(&mut self, block: Block<'a>) {
self.block = Some(block);
}
@@ -565,18 +580,34 @@ impl<'a> TextArea<'a> {
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) {
self.tab_len = len;
}
pub fn tab_length(&self) -> u8 {
self.tab_len
}
pub fn set_max_histories(&mut self, max: usize) {
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) {
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) {
self.line_number_style = Some(style);
}
@@ -585,10 +616,18 @@ impl<'a> TextArea<'a> {
self.line_number_style = None;
}
pub fn line_number_style(&self) -> Option<Style> {
self.line_number_style
}
pub fn lines(&'a self) -> &'a [String] {
&self.lines
}
pub fn into_lines(self) -> Vec<String> {
self.lines
}
/// 0-base character-wise (row, col) cursor position.
pub fn cursor(&self) -> (usize, usize) {
self.cursor