lib: Fix text view cursor update

This commit is contained in:
Erik Kundt
2024-06-27 14:20:05 +02:00
parent c554d85bc2
commit be75c62faf
2 changed files with 14 additions and 2 deletions
+1
View File
@@ -61,6 +61,7 @@ impl From<&'static dyn Any> for ViewProps {
/// A `ViewState` is the representation of a `View`s internal state. e.g. current
/// table selection or contents of a text field.
#[derive(Debug)]
pub enum ViewState {
USize(usize),
String(String),
+13 -2
View File
@@ -283,7 +283,7 @@ where
}
/// The state of a `TextArea`.
#[derive(Clone, Default)]
#[derive(Clone, Default, Debug)]
pub struct TextAreaState {
/// Current vertical scroll position.
pub scroll: usize,
@@ -529,7 +529,7 @@ impl<'a, S, M> View for TextArea<'a, S, M> {
}
/// State of a `TextView`.
#[derive(Clone, Default)]
#[derive(Clone, Default, Debug)]
pub struct TextViewState {
/// Current vertical scroll position.
pub scroll: usize,
@@ -713,6 +713,17 @@ where
None
}
fn update(&mut self, props: Option<&ViewProps>, _state: &Self::State) {
let default = TextViewProps::default();
let props = props
.and_then(|props| props.inner_ref::<TextViewProps>())
.unwrap_or(&default);
if props.cursor != self.state.cursor {
self.state.cursor = props.cursor;
}
}
fn render(&mut self, props: Option<&ViewProps>, render: RenderProps, frame: &mut Frame) {
let default = TextViewProps::default();
let props = props