Skip to main content

MarkdownState

Struct MarkdownState 

Source
pub struct MarkdownState {
Show 18 fields pub scroll: ScrollState, pub source: SourceState, pub cache: CacheState, pub display: DisplaySettings, pub collapse: CollapseState, pub expandable: ExpandableState, pub git_stats: GitStatsState, pub vim: VimState, pub selection: SelectionState, pub double_click: DoubleClickState, pub toc_hovered: bool, pub toc_hovered_entry: Option<usize>, pub toc_scroll_offset: usize, pub selection_active: bool, pub cached_git_stats: Option<GitStats>, pub rendered_lines: Vec<Line<'static>>, pub filter: Option<String>, pub filter_mode: bool, /* private fields */
}
Expand description

Unified state for the markdown widget.

This struct bundles all component states together, making it easier to manage widget state without passing many individual references.

§Example

use ratatui_toolkit::markdown_widget::state::MarkdownState;
use ratatui_toolkit::MarkdownWidget;

let mut state = MarkdownState::default();
state.source.set_content("# Hello World");

let widget = MarkdownWidget::from_state(&mut state)
    .show_toc(true)
    .show_statusline(true);

Fields§

§scroll: ScrollState

Core scroll state (position, viewport, current line).

§source: SourceState

Content source state.

§cache: CacheState

Render cache state.

§display: DisplaySettings

Display settings (line numbers, themes).

§collapse: CollapseState

Section collapse state.

§expandable: ExpandableState

Expandable content state.

§git_stats: GitStatsState

Git stats state.

§vim: VimState

Vim keybinding state.

§selection: SelectionState

Selection state for text selection/copy.

§double_click: DoubleClickState

Double-click detection state.

§toc_hovered: bool

Whether the TOC is currently hovered.

§toc_hovered_entry: Option<usize>

Index of the hovered TOC entry.

§toc_scroll_offset: usize

Scroll offset for the TOC list.

§selection_active: bool

Whether selection mode is active.

§cached_git_stats: Option<GitStats>

Git statistics for the file (cached from git_stats state).

§rendered_lines: Vec<Line<'static>>

Cached rendered lines for selection text extraction. This persists between frames so mouse events can access line data.

§filter: Option<String>

Current filter text (when in filter mode).

§filter_mode: bool

Whether filter mode is currently active.

Implementations§

Source§

impl MarkdownState

Source

pub fn inner_area(&self) -> Rect

Available on crate feature markdown-preview only.

Get the inner area for mouse event handling.

Returns the inner area that was set during the last render.

Source

pub fn set_inner_area(&mut self, area: Rect)

Available on crate feature markdown-preview only.

Set the inner area for mouse event handling.

This is typically called by the widget during render.

Source

pub fn content(&self) -> &str

Available on crate feature markdown-preview only.

Get the content from the source state.

Returns the content if set, or an empty string.

Source

pub fn update_git_stats(&mut self)

Available on crate feature markdown-preview only.

Update git stats from the source path.

This should be called periodically to refresh git information.

Source

pub fn reload_source_if_changed(&mut self) -> Result<bool, Error>

Available on crate feature markdown-preview only.

Reload file content if the watcher detected changes.

Returns true when content changed and caches were invalidated.

Source§

impl MarkdownState

Default implementation for MarkdownState.

This module is kept for compatibility but Default is now derived on the MarkdownState struct directly. Constructor for MarkdownState.

Source

pub fn new() -> MarkdownState

Available on crate feature markdown-preview only.

Create a new MarkdownState with all default values.

This is equivalent to MarkdownState::default().

Source

pub fn with_display(display: DisplaySettings) -> MarkdownState

Available on crate feature markdown-preview only.

Create a new MarkdownState with custom display settings.

Trait Implementations§

Source§

impl Clone for MarkdownState

Source§

fn clone(&self) -> MarkdownState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for MarkdownState

Source§

fn default() -> MarkdownState

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more