GitDiffModel class

A git diff viewer bubble.

Parses unified diff text and renders it with syntax highlighting, line numbers, and scrollable navigation via an embedded ViewportModel.

Example

final diff = GitDiffModel(width: 80, height: 24);
final loaded = diff.setDiff(rawDiffString);

// In update:
final (newDiff, cmd) = loaded.update(msg);

// In view:
print(loaded.view());
Inheritance

Constructors

GitDiffModel({int width = 80, int height = 24, bool showLineNumbers = true, bool wrapLines = true, bool zeroPadLineNumbers = false, DiffViewMode viewMode = DiffViewMode.unified, int horizontalOffset = 0, DiffStyles? styles, GitDiffKeyMap? keyMap, ViewportModel? viewport, List<DiffFile>? files, List<String>? renderedLines, List<DiffCommentLineHighlight>? commentHighlights, DiffLayout? layout})
Creates a new git diff model.

Properties

commentAnchors → List<DiffCommentAnchor>
Commentable anchors in the current rendered diff.
no setter
commentHighlights → List<DiffCommentLineHighlight>
Visual highlights applied to commentable diff lines.
final
files → List<DiffFile>
The parsed diff files.
no setter
hashCode → int
The hash code for this object.
no setterinherited
height → int
Height of the diff viewer in rows.
final
horizontalOffset → int
Horizontal scroll offset for side-by-side mode content.
final
keyMap → GitDiffKeyMap
Key bindings for diff viewer actions.
final
layout → DiffLayout
Shared rendered rows and source geometry for this configuration.
latefinal
renderedLines → List<String>
The full list of rendered diff text lines (all view modes, before viewport clipping). Each line is an ANSI-formatted string.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
showLineNumbers → bool
Whether to display line numbers in the gutter.
final
splitColumns → ({int gutterWidth, int leftWidth, int rightWidth})?
Effective split-panel geometry, shared with rich review hosts.
latefinal
styles → DiffStyles
The styles used for rendering.
final
totalAdditions → int
Total number of additions across all files.
latefinal
totalDeletions → int
Total number of deletions across all files.
latefinal
viewMode → DiffViewMode
Unified or side-by-side display mode.
final
viewport → ViewportModel
The embedded viewport model (exposed for widget wrapping).
no setter
width → int
Width of the diff viewer in columns.
final
wrapLines → bool
Whether to wrap long lines that exceed the viewport width.
final
zeroPadLineNumbers → bool
Whether to zero-pad line numbers (e.g. 0001) instead of space-padding (e.g. 1).
final

Methods

commentAnchorAt(int renderLine, {DiffCommentSide? side}) → DiffCommentAnchor?
Returns the comment anchor occupying renderLine, optionally preferring the requested side when multiple anchors share the same rendered row.
commentAnchorIndexAt(int renderLine, {DiffCommentSide? side}) → int?
Returns the index of the comment anchor occupying renderLine.
copyWith({int? width, int? height, bool? showLineNumbers, bool? wrapLines, bool? zeroPadLineNumbers, DiffViewMode? viewMode, int? horizontalOffset, DiffStyles? styles, GitDiffKeyMap? keyMap, ViewportModel? viewport, List<DiffFile>? files, List<String>? renderedLines, List<DiffCommentLineHighlight>? commentHighlights, DiffLayout? layout}) → GitDiffModel
Creates a copy with the given fields replaced.
init() → Cmd?
Returns an optional command to execute on program startup.
override
nearestCommentAnchor(int renderLine) → DiffCommentAnchor?
Returns the nearest comment anchor at or after renderLine.
nearestCommentAnchorIndex(int renderLine) → int
Returns the nearest comment-anchor index at or after renderLine.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
rerender() → GitDiffModel
Re-renders the existing parsed files with the current configuration.
setDiff(String rawDiff) → GitDiffModel
Sets the raw unified diff content and parses it.
toString() → String
A string representation of this object.
inherited
update(Msg msg) → (GitDiffModel, Cmd?)
Updates the component state in response to a message.
override
view() → String
Renders the current model state for display.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited