pub struct ScrollState {
pub scroll_offset: usize,
pub viewport_height: usize,
pub total_lines: usize,
pub current_line: usize,
pub filter: Option<String>,
pub filter_mode: bool,
}markdown-preview only.Expand description
Scroll state for markdown rendering.
Manages scroll position, viewport dimensions, and current line for navigation.
Fields§
§scroll_offset: usizeCurrent scroll offset (0-indexed, first visible line index).
viewport_height: usizeHeight of viewport (number of visible lines).
total_lines: usizeTotal number of lines in document.
current_line: usizeCurrently selected line (1-indexed, for highlighting).
filter: Option<String>Current filter text (when in filter mode).
filter_mode: boolWhether filter mode is currently active.
Implementations§
Source§impl ScrollState
Constructor for ScrollState.
impl ScrollState
Constructor for ScrollState.
Sourcepub fn new() -> ScrollState
pub fn new() -> ScrollState
Create a new scroll state with default settings.
Source§impl ScrollState
Adjust scroll for current line method for ScrollState.
impl ScrollState
Adjust scroll for current line method for ScrollState.
Sourcepub fn adjust_scroll_for_current_line(&mut self)
pub fn adjust_scroll_for_current_line(&mut self)
Adjust scroll offset to ensure current_line is visible with a margin. Scrolls when the cursor gets within 3 lines of the top/bottom edge.
Source§impl ScrollState
Filter line down method for ScrollState.
impl ScrollState
Filter line down method for ScrollState.
Sourcepub fn filter_line_down(&mut self, _filter_text: String)
pub fn filter_line_down(&mut self, _filter_text: String)
Move to the next line that matches the filter text.
§Arguments
filter_text- The text to match against (case-insensitive)
This method is used in filter mode to navigate through matching lines.
It updates both current_line and scroll_offset to show the next match.
Sourcepub fn filter_line_up(&mut self, _filter_text: String)
pub fn filter_line_up(&mut self, _filter_text: String)
Move to the previous line that matches the filter text.
§Arguments
filter_text- The text to match against (case-insensitive)
This method is used in filter mode to navigate through matching lines.
It updates both current_line and scroll_offset to show the previous match.
Source§impl ScrollState
Is current line visible method for ScrollState.
impl ScrollState
Is current line visible method for ScrollState.
Sourcepub fn is_current_line_visible(&self) -> bool
pub fn is_current_line_visible(&self) -> bool
Check if current line is visible in the viewport.
§Returns
true if the current line is within the visible viewport.
Source§impl ScrollState
Line down method for ScrollState.
impl ScrollState
Line down method for ScrollState.
Source§impl ScrollState
Line up method for ScrollState.
impl ScrollState
Line up method for ScrollState.
Source§impl ScrollState
Max scroll offset method for ScrollState.
impl ScrollState
Max scroll offset method for ScrollState.
Sourcepub fn max_scroll_offset(&self) -> usize
pub fn max_scroll_offset(&self) -> usize
Source§impl ScrollState
Scroll down method for ScrollState.
impl ScrollState
Scroll down method for ScrollState.
Sourcepub fn scroll_down(&mut self, amount: usize)
pub fn scroll_down(&mut self, amount: usize)
Source§impl ScrollState
Scroll percentage method for ScrollState.
impl ScrollState
Scroll percentage method for ScrollState.
Sourcepub fn scroll_percentage(&self) -> f64
pub fn scroll_percentage(&self) -> f64
Calculate percentage scrolled (0.0 to 1.0).
§Returns
The scroll position as a percentage of total scrollable content.
Source§impl ScrollState
Scroll to bottom method for ScrollState.
impl ScrollState
Scroll to bottom method for ScrollState.
Sourcepub fn scroll_to_bottom(&mut self)
pub fn scroll_to_bottom(&mut self)
Move to bottom of document.
Source§impl ScrollState
Scroll to top method for ScrollState.
impl ScrollState
Scroll to top method for ScrollState.
Sourcepub fn scroll_to_top(&mut self)
pub fn scroll_to_top(&mut self)
Move to top of document.
Source§impl ScrollState
Scroll up method for ScrollState.
impl ScrollState
Scroll up method for ScrollState.
Source§impl ScrollState
Set current line method for ScrollState.
impl ScrollState
Set current line method for ScrollState.
Sourcepub fn set_current_line(&mut self, line: usize)
pub fn set_current_line(&mut self, line: usize)
Set current line and adjust scroll to keep it visible.
§Arguments
line- The line number to set as current (1-indexed).
Source§impl ScrollState
Update total lines method for ScrollState.
impl ScrollState
Update total lines method for ScrollState.
Sourcepub fn update_total_lines(&mut self, total: usize)
pub fn update_total_lines(&mut self, total: usize)
Source§impl ScrollState
impl ScrollState
Sourcepub fn update_viewport(&mut self, area: Rect)
pub fn update_viewport(&mut self, area: Rect)
Source§impl ScrollState
Visible range method for ScrollState.
impl ScrollState
Visible range method for ScrollState.
Sourcepub fn visible_range(&self) -> (usize, usize)
pub fn visible_range(&self) -> (usize, usize)
Get range of currently visible lines (1-indexed, inclusive).
§Returns
A tuple of (start_line, end_line) for visible content.
Trait Implementations§
Source§impl Clone for ScrollState
impl Clone for ScrollState
Source§fn clone(&self) -> ScrollState
fn clone(&self) -> ScrollState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ScrollState
impl Debug for ScrollState
Source§impl Default for ScrollState
Default trait implementation for ScrollState.
impl Default for ScrollState
Default trait implementation for ScrollState.
Source§fn default() -> ScrollState
fn default() -> ScrollState
Auto Trait Implementations§
impl Freeze for ScrollState
impl RefUnwindSafe for ScrollState
impl Send for ScrollState
impl Sync for ScrollState
impl Unpin for ScrollState
impl UnsafeUnpin for ScrollState
impl UnwindSafe for ScrollState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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