diff --git a/src/ui/mod.rs b/src/ui/mod.rs index b4e0cff..7409750 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -77,6 +77,7 @@ pub struct AppState<'ws> { pub numeric_prefix: Vec, pub char_queue: Vec, pub range_select: RangeSelection, + pub dialog_scroll: u16, dirty: bool, popup: Text<'ws>, clipboard: Option, @@ -91,6 +92,7 @@ impl<'ws> Default for AppState<'ws> { numeric_prefix: Default::default(), char_queue: Default::default(), range_select: Default::default(), + dialog_scroll: 0, dirty: Default::default(), popup: Default::default(), clipboard: Default::default(), @@ -332,6 +334,12 @@ impl<'ws> Workspace<'ws> { KeyCode::Char('h') if key.modifiers == KeyModifiers::ALT => { self.exit_dialog_mode()? } + KeyCode::Char('j') | KeyCode::Down => { + self.state.dialog_scroll = self.state.dialog_scroll.saturating_add(1); + } + KeyCode::Char('k') | KeyCode::Up => { + self.state.dialog_scroll = self.state.dialog_scroll.saturating_sub(1); + } _ => { // NOOP } diff --git a/src/ui/render/dialog.rs b/src/ui/render/dialog.rs index 449696c..2dd1248 100644 --- a/src/ui/render/dialog.rs +++ b/src/ui/render/dialog.rs @@ -3,7 +3,7 @@ use ratatui::{ layout::{Constraint, Layout, Rect}, style::{Color, Style, Stylize}, text::Text, - widgets::{Block, Paragraph, Widget}, + widgets::{Block, Paragraph, Widget, Wrap}, }; pub struct Dialog<'w> { @@ -21,8 +21,8 @@ impl<'w> Dialog<'w> { } } - pub fn scroll(mut self, scroll: (u16, u16)) -> Self { - self.scroll = scroll; + pub fn scroll(mut self, line: u16) -> Self { + self.scroll.0 = line; self } } @@ -44,8 +44,10 @@ impl<'w> Widget for Dialog<'w> { let dialog_block = Block::bordered() .title_top(self.title) + .title_bottom("j,k or up,down to scroll") .style(Style::default().on_black()); let dialog = Paragraph::new(self.content.clone()) + .wrap(Wrap::default()) .scroll(self.scroll.clone()) .block(dialog_block) .style(Style::default()); diff --git a/src/ui/render/mod.rs b/src/ui/render/mod.rs index 70f69e5..e2b79af 100644 --- a/src/ui/render/mod.rs +++ b/src/ui/render/mod.rs @@ -98,41 +98,40 @@ impl<'widget, 'ws: 'widget> Widget for &'widget mut Workspace<'ws> { where Self: Sized, { - if self.state.modality() == &Modality::Dialog { // Use a popup here. let lines = Text::from_iter(self.state.popup.iter().cloned()); - let popup = dialog::Dialog::new(lines, "Help").scroll((0, 0)); + let popup = dialog::Dialog::new(lines, "Help").scroll(self.state.dialog_scroll); //let popup = Paragraph::new(lines); popup.render(area, buf); } else { - let outer_block = Block::bordered() - .title(Line::from( - self.name - .file_name() - .map(|p| p.to_string_lossy().to_string()) - .unwrap_or_else(|| String::from("Unknown")), - )) - .title_bottom(match self.state.modality() { - Modality::Navigate => "navigate", - Modality::CellEdit => "edit", - Modality::Command => "command", - Modality::Dialog => "", - Modality::RangeSelect => "range-copy", - }) - .title_bottom( - Line::from(format!( - "{},{}", - self.book.location.row, self.book.location.col + let outer_block = Block::bordered() + .title(Line::from( + self.name + .file_name() + .map(|p| p.to_string_lossy().to_string()) + .unwrap_or_else(|| String::from("Unknown")), )) - .right_aligned(), - ); + .title_bottom(match self.state.modality() { + Modality::Navigate => "navigate", + Modality::CellEdit => "edit", + Modality::Command => "command", + Modality::Dialog => "", + Modality::RangeSelect => "range-copy", + }) + .title_bottom( + Line::from(format!( + "{},{}", + self.book.location.row, self.book.location.col + )) + .right_aligned(), + ); - for (rect, f) in self.get_render_parts(area.clone()) { - f(rect, buf, self); - } + for (rect, f) in self.get_render_parts(area.clone()) { + f(rect, buf, self); + } - outer_block.render(area, buf); + outer_block.render(area, buf); } } }