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