DiffView
虚拟化的分栏或统一文件差异视图,行同步且面板可独立横向滚动。
默认不包含任何语言语法。Rust 可注册静态链接的语法;Go 和 TypeScript 可通过 LoadLanguagePack / loadLanguagePack 加载单个跨平台包,其中包含所选 Tree-sitter Wasm 语法与查询。
组件默认不带视觉样式:文本和行号继承颜色,不添加背景、边框、圆角、内边距或语法/差异配色。外观由应用显式提供样式与颜色。
#导入
启用 QuickGUI 可选的 editor crate feature,并导入差异模型与显示类型。
use quickgui::{DiffLayout, DiffView, DiffViewStyle, IntoElement, SyntaxLanguage};#用法
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")#语法高亮
DiffView 使用与 Editor 相同的内置 Tree-sitter 语法。文档、语言或语法调色板变化时,它会分别解析每个可见文件的新旧行序列,并把捕获片段分配给逻辑行。每个 RenderSide 仅在挂载时延迟构建并缓存 StyledText,再按互不重叠的字节边界合并行内新增/删除强调。滚动不会调用解析器。
#API 参考
展开条目查看说明和完整签名。短横线表示声明中未记录默认值。
DiffView
查看源码pub 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, ) -> Self查看源码from_patchpub fn from_patch(patch: &str) -> Self—
with_stylepub fn with_style(mut self, style: DiffViewStyle) -> Self—
documentpub 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) -> bool查看源码set_stylepub fn set_style(&mut self, style: DiffViewStyle) -> bool—
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查看源码DiffView::element
查看源码pub fn element(&self, id: impl Into<ElementId>) -> ElementRender a fixed header and a variable-height virtualized body.
DiffDocument
查看源码pub 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) -> Self查看源码