Skip to content

Commit

Permalink
Add scrollbar for mark list
Browse files Browse the repository at this point in the history
  • Loading branch information
unixzii committed Mar 10, 2024
1 parent 0c511ff commit 5fe858d
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/interactive/widgets/mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use tui::{
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
text::{Line, Span, Text},
widgets::{Block, Borders, Paragraph, Widget},
widgets::{
Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget,
Widget,
},
};
use tui_react::{
draw_text_nowrap_fn,
Expand Down Expand Up @@ -411,12 +414,33 @@ impl MarkPane {
inner_area
};

let line_count = marked.len();
let props = ListProps {
block: None,
entry_in_view,
};
self.list.render(props, entries, list_area, buf);

let scrollbar = Scrollbar::default()
.orientation(ScrollbarOrientation::VerticalRight)
.begin_symbol(None)
.end_symbol(None);
let mut scrollbar_state =
ScrollbarState::new(line_count).position(selected.unwrap_or(self.list.offset));

scrollbar.render(
{
let mut scrollbar_area = list_area;
// The list has no blocks, so we need to increase
// the render area for scrollbar to make sure it
// will be drawn on the border.
scrollbar_area.width += 1;
scrollbar_area
},
buf,
&mut scrollbar_state,
);

if has_focus {
let help_text = " . = o|.. = u ── ⇊ = Ctrl+d|↓ = j|⇈ = Ctrl+u|↑ = k ";
let help_text_block_width = block_width(help_text);
Expand Down

0 comments on commit 5fe858d

Please sign in to comment.