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 sourcepub fn new(document: DiffDocument) -> Selffrom_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, ) -> SelfView sourcefrom_patchpub fn from_patch(patch: &str) -> Self—
with_stylepub fn with_style(mut self, style: DiffViewStyle) -> Self—
Configures with style for this part.
pub fn with_style(mut self, style: DiffViewStyle) -> SelfView sourcedocumentpub const fn document(&self) -> &DiffDocument—
stylepub const fn style(&self) -> DiffViewStyle—
row_countpub fn row_count(&self) -> usize—
visible_rowspub fn visible_rows(&self) -> Range<usize>—
list_statepub fn list_state(&self) -> &ListState—
set_documentpub fn set_document(&mut self, document: DiffDocument) -> bool—
Configures set document for this part.
pub fn set_document(&mut self, document: DiffDocument) -> boolView sourceset_stylepub fn set_style(&mut self, style: DiffViewStyle) -> bool—
Configures set style for this part.
pub fn set_style(&mut self, style: DiffViewStyle) -> boolView sourcerefresh_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) -> boolView sourceDiffView::element
View sourcepub fn element(&self, id: impl Into<ElementId>) -> ElementRender a fixed header and a variable-height virtualized body.
DiffDocument
View sourcepub fn from_texts( old_path: impl Into<Arc<str>>, old_text: &str, new_path: impl Into<Arc<str>>, new_text: &str, ) -> SelfDiff 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) -> SelfView source