pub struct FoldingManager { /* private fields */ }Expand description
Folding manager
Implementations§
Source§impl FoldingManager
impl FoldingManager
Sourcepub fn add_region(&mut self, region: FoldRegion)
pub fn add_region(&mut self, region: FoldRegion)
Add a user-created fold region.
Sourcepub fn remove_region(&mut self, start_line: usize, end_line: usize) -> bool
pub fn remove_region(&mut self, start_line: usize, end_line: usize) -> bool
Remove a user-created fold region.
Sourcepub fn get_region_for_line(&self, line: usize) -> Option<&FoldRegion>
pub fn get_region_for_line(&self, line: usize) -> Option<&FoldRegion>
Get fold region containing specified line (merged view).
Sourcepub fn get_region_for_line_mut(
&mut self,
line: usize,
) -> Option<&mut FoldRegion>
pub fn get_region_for_line_mut( &mut self, line: usize, ) -> Option<&mut FoldRegion>
Get mutable reference to a fold region containing specified line (prefers user folds).
Sourcepub fn collapse_line(&mut self, line: usize) -> bool
pub fn collapse_line(&mut self, line: usize) -> bool
Collapse specified line
Sourcepub fn expand_line(&mut self, line: usize) -> bool
pub fn expand_line(&mut self, line: usize) -> bool
Expand specified line
Sourcepub fn toggle_line(&mut self, line: usize) -> bool
pub fn toggle_line(&mut self, line: usize) -> bool
Toggle fold state of specified line
Sourcepub fn toggle_region_starting_at_line(&mut self, start_line: usize) -> bool
pub fn toggle_region_starting_at_line(&mut self, start_line: usize) -> bool
Toggle fold region starting at specified line (preferring “innermost” region).
rust-analyzer / LSP folding ranges often contain nested regions. To make TUI and other frontends
behave more intuitively when “cursor is on a start line”, we choose:
- Among all regions with
start_line == line, the one with smallestend_line(innermost)
Sourcepub fn logical_to_visual(
&self,
logical_line: usize,
base_visual: usize,
) -> Option<usize>
pub fn logical_to_visual( &self, logical_line: usize, base_visual: usize, ) -> Option<usize>
Calculate mapping from logical line to visual line
Returns the visual line number for the specified logical line number, or None if folded
Sourcepub fn visual_to_logical(&self, visual_line: usize, base_visual: usize) -> usize
pub fn visual_to_logical(&self, visual_line: usize, base_visual: usize) -> usize
Calculate mapping from visual line to logical line
Total number of logical lines hidden by collapsed folds.
Overlapping and nested collapsed regions are counted once (the hidden ranges are merged first), so the result never exceeds the document’s logical line count.
Sourcepub fn regions(&self) -> &[FoldRegion]
pub fn regions(&self) -> &[FoldRegion]
Get all fold regions
Sourcepub fn derived_regions(&self) -> &[FoldRegion]
pub fn derived_regions(&self) -> &[FoldRegion]
Get all derived fold regions.
Sourcepub fn user_regions(&self) -> &[FoldRegion]
pub fn user_regions(&self) -> &[FoldRegion]
Get all user-created fold regions.
Sourcepub fn clear_derived_regions(&mut self)
pub fn clear_derived_regions(&mut self)
Clear all derived fold regions, leaving user folds intact.
Sourcepub fn replace_derived_regions(&mut self, regions: Vec<FoldRegion>)
pub fn replace_derived_regions(&mut self, regions: Vec<FoldRegion>)
Replace derived fold regions (will be sorted by start line and deduplicated).
Sourcepub fn replace_derived_regions_preserving_collapsed(
&mut self,
regions: Vec<FoldRegion>,
)
pub fn replace_derived_regions_preserving_collapsed( &mut self, regions: Vec<FoldRegion>, )
Replace derived fold regions while preserving collapsed state across small range drift.
Sourcepub fn replace_regions(&mut self, regions: Vec<FoldRegion>)
pub fn replace_regions(&mut self, regions: Vec<FoldRegion>)
Replace fold regions with new list (legacy API).
This replaces derived fold regions, leaving user folds intact.
Sourcepub fn expand_all(&mut self)
pub fn expand_all(&mut self)
Expand all folds
Sourcepub fn collapse_all(&mut self)
pub fn collapse_all(&mut self)
Collapse all regions
Sourcepub fn apply_line_delta(&mut self, edit_line: usize, line_delta: isize)
pub fn apply_line_delta(&mut self, edit_line: usize, line_delta: isize)
Update fold regions to account for an edit that changes the number of logical lines.
This is intended to keep user folds stable across newline insertions/deletions.
edit_lineis the logical line where the edit occurred (pre-edit).line_deltais the net change in line count (+nfor inserted newlines,-nfor deleted).
Sourcepub fn clamp_to_line_count(&mut self, line_count: usize)
pub fn clamp_to_line_count(&mut self, line_count: usize)
Clamp fold regions to the given line_count after a text edit, dropping invalid regions.