本文へスキップ

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 リファレンス

項目を展開すると説明と完全なシグネチャが表示されます。ダッシュは宣言に既定値が記載されていないことを示します。

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
ソースを見る