跳到正文

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) -> 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
查看源码
from_patchpub fn from_patch(patch: &str) -> Self—

Configures from patch for this part.

pub 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) -> Self
查看源码
documentpub const fn document(&self) -> &DiffDocument—

Configures document for this part.

pub const fn document(&self) -> &DiffDocument
查看源码
stylepub const fn style(&self) -> DiffViewStyle—

Configures style for this part.

pub const fn style(&self) -> DiffViewStyle
查看源码
row_countpub fn row_count(&self) -> usize—

Configures row count for this part.

pub fn row_count(&self) -> usize
查看源码
visible_rowspub fn visible_rows(&self) -> Range<usize>—

Configures visible rows for this part.

pub fn visible_rows(&self) -> Range<usize>
查看源码
list_statepub fn list_state(&self) -> &ListState—

Configures list state for this part.

pub 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—

Configures set style for this part.

pub 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>) -> Element

Render 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, ) -> 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
查看源码
filespub fn files(&self) -> &[DiffFile]—

Configures files for this part.

pub fn files(&self) -> &[DiffFile]
查看源码
file_countpub fn file_count(&self) -> usize—

Configures file count for this part.

pub fn file_count(&self) -> usize
查看源码
additionspub fn additions(&self) -> usize—

Configures additions for this part.

pub fn additions(&self) -> usize
查看源码
deletionspub fn deletions(&self) -> usize—

Configures deletions for this part.

pub fn deletions(&self) -> usize
查看源码
is_truncatedpub const fn is_truncated(&self) -> bool—

Configures is truncated for this part.

pub const fn is_truncated(&self) -> bool
查看源码