Fix: boundary fix in help/dict views
Some checks failed
Deploy Website / deploy (push) Failing after 31s
Some checks failed
Deploy Website / deploy (push) Failing after 31s
This commit is contained in:
@@ -96,8 +96,9 @@ pub fn prev_category(ui: &mut UiState) {
|
||||
}
|
||||
|
||||
pub fn scroll_down(ui: &mut UiState, n: usize) {
|
||||
let max = ui.dict_max_scroll.get();
|
||||
let s = ui.dict_scroll_mut();
|
||||
*s = s.saturating_add(n);
|
||||
*s = s.saturating_add(n).min(max);
|
||||
}
|
||||
|
||||
pub fn scroll_up(ui: &mut UiState, n: usize) {
|
||||
|
||||
@@ -98,8 +98,9 @@ pub fn prev_topic(ui: &mut UiState, n: usize) {
|
||||
}
|
||||
|
||||
pub fn scroll_down(ui: &mut UiState, n: usize) {
|
||||
let max = ui.help_max_scroll.get();
|
||||
let s = ui.help_scroll_mut();
|
||||
*s = s.saturating_add(n);
|
||||
*s = s.saturating_add(n).min(max);
|
||||
}
|
||||
|
||||
pub fn scroll_up(ui: &mut UiState, n: usize) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::cell::RefCell;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use cagire_markdown::ParsedMarkdown;
|
||||
@@ -57,6 +57,8 @@ pub struct UiState {
|
||||
pub dict_scrolls: Vec<usize>,
|
||||
pub dict_search_query: String,
|
||||
pub dict_search_active: bool,
|
||||
pub help_max_scroll: Cell<usize>,
|
||||
pub dict_max_scroll: Cell<usize>,
|
||||
pub help_collapsed: Vec<bool>,
|
||||
pub help_on_section: Option<usize>,
|
||||
pub dict_collapsed: Vec<bool>,
|
||||
@@ -107,6 +109,8 @@ impl Default for UiState {
|
||||
dict_scrolls: vec![0; crate::model::categories::category_count()],
|
||||
dict_search_query: String::new(),
|
||||
dict_search_active: false,
|
||||
help_max_scroll: Cell::new(usize::MAX),
|
||||
dict_max_scroll: Cell::new(usize::MAX),
|
||||
help_collapsed: vec![false; crate::model::docs::section_count()],
|
||||
help_on_section: None,
|
||||
dict_collapsed: vec![false; crate::model::categories::section_count()],
|
||||
|
||||
@@ -160,6 +160,7 @@ fn render_words(frame: &mut Frame, app: &App, area: Rect, is_searching: bool) {
|
||||
let visible_height = content_area.height.saturating_sub(2) as usize;
|
||||
let total_lines = lines.len();
|
||||
let max_scroll = total_lines.saturating_sub(visible_height);
|
||||
app.ui.dict_max_scroll.set(max_scroll);
|
||||
let scroll = app.ui.dict_scroll().min(max_scroll);
|
||||
|
||||
let title = if is_searching {
|
||||
|
||||
@@ -223,6 +223,7 @@ fn render_content(frame: &mut Frame, app: &App, area: Rect) {
|
||||
.map(|l| wrapped_line_count(l, content_width))
|
||||
.sum();
|
||||
let max_scroll = total_wrapped.saturating_sub(visible_height);
|
||||
app.ui.help_max_scroll.set(max_scroll);
|
||||
let scroll = app.ui.help_scroll().min(max_scroll);
|
||||
|
||||
let mut lines = parsed.lines.clone();
|
||||
|
||||
Reference in New Issue
Block a user