pub struct DiffState { /* private fields */ }Expand description
Retained focus, viewport, context expansion and selection for a
super::Diff showing one or more files of a patch.
Create once in the owning view. Mutations notify observers; the application owns the patch and chooses when to install new files. Syntax and inline emphasis are prepared on a background thread and appear once ready.
Implementations§
Source§impl DiffState
impl DiffState
Sourcepub fn new(
files: impl IntoIterator<Item = DiffFile>,
cx: &mut Context<'_, Self>,
) -> Self
pub fn new( files: impl IntoIterator<Item = DiffFile>, cx: &mut Context<'_, Self>, ) -> Self
Creates a unified viewer with three unchanged lines around each change.
Sourcepub fn with_mode(self, mode: DiffMode) -> Self
pub fn with_mode(self, mode: DiffMode) -> Self
Sets the initial display mode. Default is DiffMode::Unified.
Sourcepub fn with_context_lines(self, lines: Option<usize>) -> Self
pub fn with_context_lines(self, lines: Option<usize>) -> Self
Sets the initial unchanged context around each change. Default is
Some(3); None shows every supplied patch line.
Sourcepub fn with_expansion_lines(self, lines: usize) -> Self
pub fn with_expansion_lines(self, lines: usize) -> Self
Sets how many lines an up or down disclosure reveals. Default is 20.
Sourcepub fn with_min_collapsed_lines(self, lines: usize) -> Self
pub fn with_min_collapsed_lines(self, lines: usize) -> Self
Sets the shortest unchanged range that collapses; shorter ranges stay visible. Default is 2.
Sourcepub fn with_inline_unit(self, unit: Option<DiffInlineUnit>) -> Self
pub fn with_inline_unit(self, unit: Option<DiffInlineUnit>) -> Self
Sets the unit inline changes between paired lines are emphasized in,
or None to emphasize whole lines only. Default is DiffInlineUnit::Word.
Sourcepub fn with_inline_max_line_length(self, length: usize) -> Self
pub fn with_inline_max_line_length(self, length: usize) -> Self
Sets the longest line, in bytes, compared for inline changes. Default is 1,000.
Sourcepub fn with_syntax_max_line_length(self, length: usize) -> Self
pub fn with_syntax_max_line_length(self, length: usize) -> Self
Sets the longest line, in bytes, given syntax emphasis. Default is 1,000.
Sourcepub fn set_expansion_lines(&mut self, lines: usize, cx: &mut Context<'_, Self>)
pub fn set_expansion_lines(&mut self, lines: usize, cx: &mut Context<'_, Self>)
Changes the number of lines each disclosure reveals, preserving selection and scrolling.
Sourcepub fn set_min_collapsed_lines(
&mut self,
lines: usize,
cx: &mut Context<'_, Self>,
)
pub fn set_min_collapsed_lines( &mut self, lines: usize, cx: &mut Context<'_, Self>, )
Changes the shortest unchanged range that collapses, preserving selection and scrolling.
Sourcepub fn set_inline_unit(
&mut self,
unit: Option<DiffInlineUnit>,
cx: &mut Context<'_, Self>,
)
pub fn set_inline_unit( &mut self, unit: Option<DiffInlineUnit>, cx: &mut Context<'_, Self>, )
Changes the inline comparison unit without resetting selection or scrolling.
Sourcepub fn set_inline_max_line_length(
&mut self,
length: usize,
cx: &mut Context<'_, Self>,
)
pub fn set_inline_max_line_length( &mut self, length: usize, cx: &mut Context<'_, Self>, )
Changes the inline comparison line limit in bytes without resetting selection or scrolling.
Sourcepub fn set_syntax_max_line_length(
&mut self,
length: usize,
cx: &mut Context<'_, Self>,
)
pub fn set_syntax_max_line_length( &mut self, length: usize, cx: &mut Context<'_, Self>, )
Changes the syntax emphasis line limit in bytes without resetting selection or scrolling.
pub fn mode(&self) -> DiffMode
pub fn context_lines(&self) -> Option<usize>
pub fn expansion_lines(&self) -> usize
pub fn min_collapsed_lines(&self) -> usize
pub fn inline_unit(&self) -> Option<DiffInlineUnit>
pub fn inline_max_line_length(&self) -> usize
pub fn syntax_max_line_length(&self) -> usize
pub fn selected_lines(&self) -> Option<DiffLineRange>
Sourcepub fn is_file_collapsed(&self, path: &str) -> bool
pub fn is_file_collapsed(&self, path: &str) -> bool
Whether the file at path shows only its header.
Sourcepub fn set_files(
&mut self,
files: impl IntoIterator<Item = DiffFile>,
cx: &mut Context<'_, Self>,
)
pub fn set_files( &mut self, files: impl IntoIterator<Item = DiffFile>, cx: &mut Context<'_, Self>, )
Replaces the files and resets expansion, selection and viewport. Collapsed files stay collapsed when their path is still present.
Sourcepub fn set_mode(&mut self, mode: DiffMode, cx: &mut Context<'_, Self>)
pub fn set_mode(&mut self, mode: DiffMode, cx: &mut Context<'_, Self>)
Changes the display mode while preserving source-line selection and a nearby source row.
Sourcepub fn set_context_lines(
&mut self,
lines: Option<usize>,
cx: &mut Context<'_, Self>,
)
pub fn set_context_lines( &mut self, lines: Option<usize>, cx: &mut Context<'_, Self>, )
Sets surrounding context. None shows every supplied patch line.
Sourcepub fn expand_unchanged(&mut self, cx: &mut Context<'_, Self>)
pub fn expand_unchanged(&mut self, cx: &mut Context<'_, Self>)
Reveals all unchanged source while preserving the configured context count.
Sourcepub fn collapse_unchanged(&mut self, cx: &mut Context<'_, Self>)
pub fn collapse_unchanged(&mut self, cx: &mut Context<'_, Self>)
Restores the configured context disclosures.
Sourcepub fn set_file_collapsed(
&mut self,
path: &str,
collapsed: bool,
cx: &mut Context<'_, Self>,
)
pub fn set_file_collapsed( &mut self, path: &str, collapsed: bool, cx: &mut Context<'_, Self>, )
Collapses the file at path to its header, or expands it, without
emitting a user event.
Sourcepub fn conflict_resolution(
&self,
path: &str,
ix: usize,
) -> Option<DiffConflictResolution>
pub fn conflict_resolution( &self, path: &str, ix: usize, ) -> Option<DiffConflictResolution>
The resolution of conflict ix in the file at path, if any.
Use DiffFile::conflicts to enumerate valid indices; None means
unresolved, or that the file or index does not exist.
Sourcepub fn resolve_conflict(
&mut self,
path: &str,
ix: usize,
resolution: Option<DiffConflictResolution>,
cx: &mut Context<'_, Self>,
)
pub fn resolve_conflict( &mut self, path: &str, ix: usize, resolution: Option<DiffConflictResolution>, cx: &mut Context<'_, Self>, )
Resolves conflict ix (an index in DiffFile::conflicts) in the file
at path, or clears its resolution
with None, without emitting a user event.
Sourcepub fn resolved_text(&self, path: &str) -> Option<String>
pub fn resolved_text(&self, path: &str) -> Option<String>
The working file with every conflict replaced by its resolution, or
None while a conflict is unresolved or path names no conflicted file.
Sourcepub fn set_selected_lines(
&mut self,
range: Option<DiffLineRange>,
cx: &mut Context<'_, Self>,
)
pub fn set_selected_lines( &mut self, range: Option<DiffLineRange>, cx: &mut Context<'_, Self>, )
Synchronizes source-line selection without emitting a user event. Clips to supplied patch lines; a range containing none clears selection.
Sourcepub fn selected_text(&self, cx: &App) -> String
pub fn selected_text(&self, cx: &App) -> String
Returns selected source without gutters, diff markers or annotation content.
Sourcepub fn scroll_to_line(
&mut self,
position: DiffLinePosition,
cx: &mut Context<'_, Self>,
)
pub fn scroll_to_line( &mut self, position: DiffLinePosition, cx: &mut Context<'_, Self>, )
Reveals and scrolls to a source line, expanding its file and hidden context if needed.
Sourcepub fn scroll_to_file(&mut self, path: &str, cx: &mut Context<'_, Self>)
pub fn scroll_to_file(&mut self, path: &str, cx: &mut Context<'_, Self>)
Scrolls to the header of the file at path, a DiffFile::path.
Sourcepub fn next_change(&mut self, cx: &mut Context<'_, Self>)
pub fn next_change(&mut self, cx: &mut Context<'_, Self>)
Moves to the next changed group after the current viewport, across files.
Sourcepub fn previous_change(&mut self, cx: &mut Context<'_, Self>)
pub fn previous_change(&mut self, cx: &mut Context<'_, Self>)
Moves to the previous changed group before the current viewport, across files.
Trait Implementations§
impl EventEmitter<DiffEvent> for DiffState
Source§impl Focusable for DiffState
impl Focusable for DiffState
Source§fn focus_handle(&self, _: &App) -> FocusHandle
fn focus_handle(&self, _: &App) -> FocusHandle
Auto Trait Implementations§
impl !RefUnwindSafe for DiffState
impl !Send for DiffState
impl !Sync for DiffState
impl !UnwindSafe for DiffState
impl Freeze for DiffState
impl Unpin for DiffState
impl UnsafeUnpin for DiffState
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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