Skip to main content

DiffState

Struct DiffState 

Source
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

Source

pub fn new( files: impl IntoIterator<Item = DiffFile>, cx: &mut Context<'_, Self>, ) -> Self

Creates a unified viewer with three unchanged lines around each change.

Source

pub fn with_mode(self, mode: DiffMode) -> Self

Sets the initial display mode. Default is DiffMode::Unified.

Source

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.

Source

pub fn with_expansion_lines(self, lines: usize) -> Self

Sets how many lines an up or down disclosure reveals. Default is 20.

Source

pub fn with_min_collapsed_lines(self, lines: usize) -> Self

Sets the shortest unchanged range that collapses; shorter ranges stay visible. Default is 2.

Source

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.

Source

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.

Source

pub fn with_syntax_max_line_length(self, length: usize) -> Self

Sets the longest line, in bytes, given syntax emphasis. Default is 1,000.

Source

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.

Source

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.

Source

pub fn set_inline_unit( &mut self, unit: Option<DiffInlineUnit>, cx: &mut Context<'_, Self>, )

Changes the inline comparison unit without resetting selection or scrolling.

Source

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.

Source

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.

Source

pub fn files(&self) -> &[DiffFile]

The files in patch order.

Source

pub fn mode(&self) -> DiffMode

Source

pub fn context_lines(&self) -> Option<usize>

Source

pub fn expansion_lines(&self) -> usize

Source

pub fn min_collapsed_lines(&self) -> usize

Source

pub fn inline_unit(&self) -> Option<DiffInlineUnit>

Source

pub fn inline_max_line_length(&self) -> usize

Source

pub fn syntax_max_line_length(&self) -> usize

Source

pub fn selected_lines(&self) -> Option<DiffLineRange>

Source

pub fn is_file_collapsed(&self, path: &str) -> bool

Whether the file at path shows only its header.

Source

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.

Source

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.

Source

pub fn set_context_lines( &mut self, lines: Option<usize>, cx: &mut Context<'_, Self>, )

Sets surrounding context. None shows every supplied patch line.

Source

pub fn expand_unchanged(&mut self, cx: &mut Context<'_, Self>)

Reveals all unchanged source while preserving the configured context count.

Source

pub fn collapse_unchanged(&mut self, cx: &mut Context<'_, Self>)

Restores the configured context disclosures.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn selected_text(&self, cx: &App) -> String

Returns selected source without gutters, diff markers or annotation content.

Source

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.

Source

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.

Source

pub fn next_change(&mut self, cx: &mut Context<'_, Self>)

Moves to the next changed group after the current viewport, across files.

Source

pub fn previous_change(&mut self, cx: &mut Context<'_, Self>)

Moves to the previous changed group before the current viewport, across files.

Trait Implementations§

Source§

impl EventEmitter<DiffEvent> for DiffState

Source§

impl Focusable for DiffState

Source§

fn focus_handle(&self, _: &App) -> FocusHandle

Returns the focus handle associated with this view.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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