Skip to content

DiffView

A virtualized split or unified file diff with synchronized rows and independent pane scrolling.

No language grammars are included by default. Register a linked grammar in Rust, or load one portable pack of selected Tree-sitter Wasm grammars and queries using loadLanguagePack (TypeScript) / LoadLanguagePack (Go).

Unstyled by default: text and line-number colors inherit, and the component adds no background, border, rounding, padding, or syntax/diff palette. Supply application styles and explicit colors to opt into an appearance.

#Import

Enable QuickGUI's opt-in editor crate feature and import the diff model and presentation types.

use quickgui::{DiffLayout, DiffView, DiffViewStyle, IntoElement, SyntaxLanguage};

#Usage

let diff = DiffView::from_texts(
    "before.rs",
    "pub const ANSWER: u8 = 41;\n",
    "after.rs",
    "pub const ANSWER: u8 = 42;\n",
)
.with_style(
    DiffViewStyle::default()
        .layout(DiffLayout::Split)
        .language(Some(SyntaxLanguage::Rust)),
);

diff.element("source-diff")

#Syntax highlighting

DiffView uses the same registered Tree-sitter grammars as Editor. When its document, language, or syntax palette changes, it parses each visible old/new file lane once and assigns capture fragments to logical rows. Each RenderSide then builds and caches its StyledText lazily when mounted, merging inline addition/deletion emphasis at non-overlapping byte boundaries. Scrolling never invokes the parser.

#API reference

Expand an entry for its description and complete signature. A dash means no declaration default is documented.

DiffView

View source
pub fn new(document: DiffDocument) -> Self
from_textspub fn from_texts( old_path: impl Into<Arc<str>>, old_text: &str, new_path: impl Into<Arc<str>>, new_text: &str, ) -> Self—

Configures from texts for this part.

pub fn from_texts( old_path: impl Into<Arc<str>>, old_text: &str, new_path: impl Into<Arc<str>>, new_text: &str, ) -> Self
View source
from_patchpub fn from_patch(patch: &str) -> Self—

Configures from patch for this part.

pub fn from_patch(patch: &str) -> Self
View source
with_stylepub fn with_style(mut self, style: DiffViewStyle) -> Self—

Configures with style for this part.

pub fn with_style(mut self, style: DiffViewStyle) -> Self
View source
documentpub const fn document(&self) -> &DiffDocument—

Configures document for this part.

pub const fn document(&self) -> &DiffDocument
View source
stylepub const fn style(&self) -> DiffViewStyle—

Configures style for this part.

pub const fn style(&self) -> DiffViewStyle
View source
row_countpub fn row_count(&self) -> usize—

Configures row count for this part.

pub fn row_count(&self) -> usize
View source
visible_rowspub fn visible_rows(&self) -> Range<usize>—

Configures visible rows for this part.

pub fn visible_rows(&self) -> Range<usize>
View source
list_statepub fn list_state(&self) -> &ListState—

Configures list state for this part.

pub fn list_state(&self) -> &ListState
View source
set_documentpub fn set_document(&mut self, document: DiffDocument) -> bool—

Configures set document for this part.

pub fn set_document(&mut self, document: DiffDocument) -> bool
View source
set_stylepub fn set_style(&mut self, style: DiffViewStyle) -> bool—

Configures set style for this part.

pub fn set_style(&mut self, style: DiffViewStyle) -> bool
View source
refresh_syntax_languagespub fn refresh_syntax_languages(&mut self) -> bool—

Refresh registered language inference and injections while retaining scroll anchors.

pub fn refresh_syntax_languages(&mut self) -> bool
View source

DiffView::element

View source
pub fn element(&self, id: impl Into<ElementId>) -> Element

Render a fixed header and a variable-height virtualized body.

DiffDocument

View source
pub fn from_texts( old_path: impl Into<Arc<str>>, old_text: &str, new_path: impl Into<Arc<str>>, new_text: &str, ) -> Self

Diff two complete in-memory files with Zed's histogram algorithm and Git-like hunk sliding.

from_patchpub fn from_patch(patch: &str) -> Self—

Parse a captured Git or ordinary unified patch. Malformed lines are skipped safely.

pub fn from_patch(patch: &str) -> Self
View source
filespub fn files(&self) -> &[DiffFile]—

Configures files for this part.

pub fn files(&self) -> &[DiffFile]
View source
file_countpub fn file_count(&self) -> usize—

Configures file count for this part.

pub fn file_count(&self) -> usize
View source
additionspub fn additions(&self) -> usize—

Configures additions for this part.

pub fn additions(&self) -> usize
View source
deletionspub fn deletions(&self) -> usize—

Configures deletions for this part.

pub fn deletions(&self) -> usize
View source
is_truncatedpub const fn is_truncated(&self) -> bool—

Configures is truncated for this part.

pub const fn is_truncated(&self) -> bool
View source