diff --git a/src/cursor.rs b/src/cursor.rs index 0ad7c8c..be90af6 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -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]))), diff --git a/src/history.rs b/src/history.rs index fdccb2a..ab554d7 100644 --- a/src/history.rs +++ b/src/history.rs @@ -140,4 +140,8 @@ impl History { edit.undo(lines); Some(edit.cursor_before()) } + + pub fn max_items(&self) -> usize { + self.max_items + } } diff --git a/src/textarea.rs b/src/textarea.rs index b3cbd43..2e45b0a 100644 --- a/src/textarea.rs +++ b/src/textarea.rs @@ -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