ratatui_toolkit/widgets/markdown_widget/state/source_state/methods/reload_source.rs
1//! Reload source method for SourceState.
2
3use crate::widgets::markdown_widget::state::source_state::SourceState;
4
5impl SourceState {
6 /// Reload the source content from disk (for file-based sources).
7 ///
8 /// This re-reads the file. The caller should check the return value
9 /// and invalidate caches if content changed.
10 ///
11 /// For string-based sources, this is a no-op.
12 ///
13 /// # Returns
14 ///
15 /// * `Ok(true)` - Content changed, caller should invalidate caches.
16 /// * `Ok(false)` - Content unchanged or source is string-based.
17 ///
18 /// # Errors
19 ///
20 /// Returns an error if the file cannot be read.
21 pub fn reload_source(&mut self) -> std::io::Result<bool> {
22 if let Some(ref mut source) = self.source {
23 let changed = source.reload()?;
24 if changed {
25 self.line_count = source.content().lines().count();
26 }
27 Ok(changed)
28 } else {
29 Ok(false)
30 }
31 }
32}