Radish alpha
r
rad:z39mP9rQAaGmERfUMPULfPUi473tY
Radicle terminal user interface
Radicle
Git
Remove text from `TextViewState`
Merged did:key:z6MkgFq6...nBGz opened 1 year ago
3 files changed +32 -40 d857d1ea 976346c4
modified bin/commands/patch/review.rs
@@ -112,13 +112,13 @@ impl Tui {
}

#[derive(Clone, Debug)]
-
pub enum Message<'a> {
+
pub enum Message {
    ShowMain,
    PanesChanged { state: PanesState },
    HunkChanged { state: TableState },
    HunkViewChanged { state: DiffViewState },
    ShowHelp,
-
    HelpChanged { state: TextViewState<'a> },
+
    HelpChanged { state: TextViewState },
    Comment,
    Accept,
    Discard,
@@ -200,7 +200,7 @@ pub struct App<'a> {
    /// State of panes widget on the main page.
    group: PanesState,
    /// State of text view widget on the help page.
-
    help: TextViewState<'a>,
+
    help: TextViewState,
}

impl<'a> TryFrom<Tui> for App<'a> {
@@ -258,7 +258,7 @@ impl<'a> App<'a> {
            ))),
            page: AppPage::Main,
            group: PanesState::new(2, Some(0)),
-
            help: TextViewState::new(help_text(), Position::default()),
+
            help: TextViewState::new(Position::default()),
        };

        app.reload_states()?;
@@ -361,7 +361,7 @@ impl<'a> App<'a> {
}

impl<'a> App<'a> {
-
    fn show_hunk_list(&self, ui: &mut Ui<Message<'a>>, frame: &mut Frame) {
+
    fn show_hunk_list(&self, ui: &mut Ui<Message>, frame: &mut Frame) {
        let header = [Column::new(" Hunks ", Constraint::Fill(1))].to_vec();
        let columns = [
            Column::new("", Constraint::Length(2)),
@@ -381,7 +381,7 @@ impl<'a> App<'a> {
        }
    }

-
    fn show_hunk(&self, ui: &mut Ui<Message<'a>>, frame: &mut Frame) {
+
    fn show_hunk(&self, ui: &mut Ui<Message>, frame: &mut Frame) {
        let hunks = self.hunks.lock().unwrap();

        let selected = hunks.selected();
@@ -414,7 +414,7 @@ impl<'a> App<'a> {
        }
    }

-
    fn show_context_bar(&self, ui: &mut Ui<Message<'a>>, frame: &mut Frame) {
+
    fn show_context_bar(&self, ui: &mut Ui<Message>, frame: &mut Frame) {
        let hunks = &self.hunks.lock().unwrap().items;

        let id = format!(" {} ", format::cob(&self.patch));
@@ -470,8 +470,8 @@ impl<'a> App<'a> {
    }
}

-
impl<'a> Show<Message<'a>> for App<'a> {
-
    fn show(&self, ctx: &Context<Message<'a>>, frame: &mut Frame) -> Result<(), anyhow::Error> {
+
impl<'a> Show<Message> for App<'a> {
+
    fn show(&self, ctx: &Context<Message>, frame: &mut Frame) -> Result<(), anyhow::Error> {
        Window::default().show(ctx, |ui| {
            let mut page_focus = self.group.focus();

@@ -525,13 +525,13 @@ impl<'a> Show<Message<'a>> for App<'a> {
                            ui.columns(frame, header, Some(Borders::Top));
                            let help = ui.text_view(
                                frame,
-
                                self.help.text().to_string(),
+
                                help_text().to_string(),
                                &mut cursor,
                                Some(Borders::BottomSides),
                            );
                            if help.changed {
                                ui.send_message(Message::HelpChanged {
-
                                    state: TextViewState::new(self.help.text().clone(), cursor),
+
                                    state: TextViewState::new(cursor),
                                })
                            }
                        });
@@ -555,10 +555,10 @@ impl<'a> Show<Message<'a>> for App<'a> {
    }
}

-
impl<'a> store::Update<Message<'a>> for App<'a> {
+
impl<'a> store::Update<Message> for App<'a> {
    type Return = Selection;

-
    fn update(&mut self, message: Message<'a>) -> Option<Exit<Self::Return>> {
+
    fn update(&mut self, message: Message) -> Option<Exit<Self::Return>> {
        log::info!("Received message: {:?}", message);

        match message {
modified bin/commands/patch/select/imui.rs
@@ -49,7 +49,7 @@ Pattern: is:<state> | is:authored | authors:[<did>, <did>] | <search>
Example:    is:open is:authored improve"#;

#[derive(Clone, Debug)]
-
pub enum Message<'a> {
+
pub enum Message {
    Quit,
    Exit {
        operation: Option<PatchOperation>,
@@ -65,7 +65,7 @@ pub enum Message<'a> {
        page: Page,
    },
    HelpChanged {
-
        state: TextViewState<'a>,
+
        state: TextViewState,
    },
    ShowSearch,
    UpdateSearch {
@@ -88,7 +88,7 @@ pub struct Storage {
}

#[derive(Clone, Debug)]
-
pub struct App<'a> {
+
pub struct App {
    storage: Storage,
    mode: Mode,
    page: Page,
@@ -96,11 +96,11 @@ pub struct App<'a> {
    patches: TableState,
    search: BufferedValue<TextEditState>,
    show_search: bool,
-
    help: TextViewState<'a>,
+
    help: TextViewState,
    filter: PatchItemFilter,
}

-
impl<'a> TryFrom<&Context> for App<'a> {
+
impl TryFrom<&Context> for App {
    type Error = anyhow::Error;

    fn try_from(context: &Context) -> Result<Self, Self::Error> {
@@ -132,16 +132,16 @@ impl<'a> TryFrom<&Context> for App<'a> {
                cursor: search.len(),
            }),
            show_search: false,
-
            help: TextViewState::new(HELP, Position::default()),
+
            help: TextViewState::new(Position::default()),
            filter,
        })
    }
}

-
impl<'a> store::Update<Message<'a>> for App<'a> {
+
impl store::Update<Message> for App {
    type Return = Selection;

-
    fn update(&mut self, message: Message<'a>) -> Option<tui::Exit<Selection>> {
+
    fn update(&mut self, message: Message) -> Option<tui::Exit<Selection>> {
        log::debug!("[State] Received message: {:?}", message);

        match message {
@@ -214,7 +214,7 @@ impl<'a> store::Update<Message<'a>> for App<'a> {
    }
}

-
impl<'a> Show<Message<'a>> for App<'a> {
+
impl Show<Message> for App {
    fn show(&self, ctx: &im::Context<Message>, frame: &mut Frame) -> Result<()> {
        Window::default().show(ctx, |ui| {
            match self.page {
@@ -328,13 +328,13 @@ impl<'a> Show<Message<'a>> for App<'a> {

                        let text_view = ui.text_view(
                            frame,
-
                            self.help.text().to_string(),
+
                            HELP.to_string(),
                            &mut cursor,
                            Some(Borders::BottomSides),
                        );
                        if text_view.changed {
                            ui.send_message(Message::HelpChanged {
-
                                state: TextViewState::new(self.help.text().to_string(), cursor),
+
                                state: TextViewState::new(cursor),
                            })
                        }

@@ -380,7 +380,7 @@ impl<'a> Show<Message<'a>> for App<'a> {
    }
}

-
impl<'a> App<'a> {
+
impl App {
    pub fn show_patches(&self, frame: &mut Frame, ui: &mut im::Ui<Message>) {
        let patches = self
            .storage
@@ -448,7 +448,7 @@ impl<'a> App<'a> {
    }
}

-
impl<'a> App<'a> {
+
impl App {
    pub fn selected_patch(&self) -> Option<&PatchItem> {
        let patches = self
            .storage
modified src/ui/im/widget.rs
@@ -661,21 +661,13 @@ impl<'a> Widget for Bar<'a> {
}

#[derive(Clone, Debug)]
-
pub struct TextViewState<'a> {
-
    text: Text<'a>,
+
pub struct TextViewState {
    cursor: Position,
}

-
impl<'a> TextViewState<'a> {
-
    pub fn new(text: impl Into<Text<'a>>, cursor: Position) -> Self {
-
        Self {
-
            text: text.into(),
-
            cursor,
-
        }
-
    }
-

-
    pub fn text(&self) -> &Text<'a> {
-
        &self.text
+
impl TextViewState {
+
    pub fn new(cursor: Position) -> Self {
+
        Self { cursor }
    }

    pub fn cursor(&self) -> Position {
@@ -683,7 +675,7 @@ impl<'a> TextViewState<'a> {
    }
}

-
impl<'a> TextViewState<'a> {
+
impl TextViewState {
    fn scroll_up(&mut self) {
        self.cursor.x = self.cursor.x.saturating_sub(1);
    }
@@ -802,7 +794,7 @@ impl<'a> Widget for TextView<'a> {
            text_area,
        );

-
        let mut state = TextViewState::new(self.text.clone(), *self.cursor);
+
        let mut state = TextViewState::new(*self.cursor);

        if let Some(key) = ui.input_with_key(|_| true) {
            let lines = self.text.lines.clone();