Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
lib: Fix text view cursor update
Erik Kundt committed 1 year ago
commit be75c62fafcf888cad1a2bb9f415c3957bd6c41b
parent c554d85bc262fa40f95b0ad64693c248c0da45a2
2 files changed +14 -2
modified src/ui/widget.rs
@@ -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),
modified src/ui/widget/input.rs
@@ -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