ratatui_toolkit/widgets/markdown_widget/state/cache_state/
render_cache.rs

1//! Cache for rendered markdown lines.
2//!
3//! This cache stores rendered lines that depend on rendering width.
4
5use crate::widgets::markdown_widget::foundation::elements::CodeBlockTheme;
6use ratatui::text::Line;
7
8/// Cache for rendered markdown lines (depends on width).
9#[derive(Debug, Clone)]
10pub struct RenderCache {
11    /// Hash of the content that was rendered.
12    pub content_hash: u64,
13    /// Width used for rendering.
14    pub width: usize,
15    /// Whether line numbers were shown.
16    pub show_line_numbers: bool,
17    /// Theme used for rendering.
18    pub theme: CodeBlockTheme,
19    /// Hash of the app theme (for cache invalidation on theme change).
20    pub app_theme_hash: u64,
21    /// Whether heading collapse indicators were shown.
22    pub show_heading_collapse: bool,
23    /// Cached rendered lines.
24    pub lines: Vec<Line<'static>>,
25    /// Line boundaries: (start_visual_idx, visual_line_count) for each logical line.
26    pub line_boundaries: Vec<(usize, usize)>,
27}
28
29impl RenderCache {
30    /// Create a new render cache.
31    #[allow(clippy::too_many_arguments)]
32    pub fn new(
33        content_hash: u64,
34        width: usize,
35        show_line_numbers: bool,
36        theme: CodeBlockTheme,
37        app_theme_hash: u64,
38        show_heading_collapse: bool,
39        lines: Vec<Line<'static>>,
40        line_boundaries: Vec<(usize, usize)>,
41    ) -> Self {
42        Self {
43            content_hash,
44            width,
45            show_line_numbers,
46            theme,
47            app_theme_hash,
48            show_heading_collapse,
49            lines,
50            line_boundaries,
51        }
52    }
53}