workspacediff

package
v1.17.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package workspacediff is the shared Diff preview model.

The project Workspaces plugin and the global Workspaces preview both draw the same working-tree + commits view. This package owns snapshot load, first-commit load (short vs full hash), that render, and the inner pointer rules (HandleClick / HandleWheel). A host that registers FileHits must dispatch those hits here rather than re-implementing selection. Neither surface constructs the other.

Index

Constants

View Source
const (
	RegionDivider      = "diff-tab-divider"
	RegionFile         = "diff-tab-file"
	RegionCommit       = "diff-tab-commit"
	RegionDiffPane     = "diff-tab-diff-pane"
	RegionPreviewFile  = "diff-tab-preview-file"
	RegionFileListPane = "diff-tab-filelist-pane"
	RegionCommitBack   = "commit-file-back"
	RegionCommitFile   = "commit-file-item"
	RegionCommitDiff   = "commit-file-diff-pane"
	RegionMinimap      = "diff-tab-minimap"
)
View Source
const (
	MaxUntrackedFileSize   = 1 << 20
	MaxUntrackedFiles      = 50
	MaxUntrackedTotalBytes = 4 << 20
)
View Source
const CollapseThreshold = 120

CollapseThreshold is the minimum width for the two-pane Diff layout.

View Source
const (

	// ContentInset is the columns of padding the Diff body keeps on each side,
	// matching the issue pane's horizontal content padding.
	ContentInset = 1
)
View Source
const IdentityWorkingTree = "wt"

IdentityWorkingTree is TargetWorkingTree.Identity(). Never "HEAD".

View Source
const MaxDiffBytes = 768 << 10

MaxDiffBytes bounds git patch output before parsing or transport encoding. The encoded content response has its own cap because JSON may expand bytes.

Variables

This section is empty.

Functions

func CommitDetailMatchesListHash

func CommitDetailMatchesListHash(detail *CommitDetail, listHash string) bool

CommitDetailMatchesListHash reports whether a loaded commit is the list row. The list stores git %h; detail stores %H in Hash and %h in ShortHash.

func ContentBox added in v1.0.0

func ContentBox(leaf mouse.Rect) mouse.Rect

ContentBox is the box the Diff body is drawn in: the leaf inset by ContentInset on the left and right. Render and every hit region go through this one function, so a click lands on the row that was drawn.

func DetectDefaultBranch

func DetectDefaultBranch(ctx context.Context, workdir string) string

DetectDefaultBranch finds the repo's default branch (remote HEAD, then main/master).

func IsBodyRegion added in v1.1.0

func IsBodyRegion(id string) bool

IsBodyRegion reports an inner Diff hit: a file or commit row, a pane, the list/hunk divider, or the full-file minimap. Hosts register these from FileHits/DividerHit and must dispatch them through HandleClick / HandleWheel rather than re-implementing the selection rules. Tab chips are not included.

func LoadCommitFileDiff added in v1.12.0

func LoadCommitFileDiff(ctx context.Context, workdir, hash, path, parentHash string) (string, error)

LoadCommitFileDiff loads one path's patch from a commit, diffing against parentHash for merges so combined diffs do not come back empty.

func LoadRangeCmd added in v1.0.0

func LoadRangeCmd(workdir string, t Target, epoch uint64, workspaceID string) tea.Cmd

LoadRangeCmd runs one git diff for a range target.

func LoadRangeDiff added in v1.12.0

func LoadRangeDiff(ctx context.Context, workdir string, t Target) (string, error)

LoadRangeDiff runs git diff --binary for a range target.

func LoadSnapshotCmd

func LoadSnapshotCmd(workdir, baseRef, workspaceID string) tea.Cmd

LoadSnapshotCmd loads a snapshot for workdir and tags it with workspaceID.

func LoadSnapshotCmdAt added in v1.0.0

func LoadSnapshotCmdAt(workdir, baseRef, workspaceID string, epoch uint64, identity string) tea.Cmd

LoadSnapshotCmdAt is LoadSnapshotCmd with epoch and target identity.

func LoadSnapshotCmdBound added in v1.2.0

func LoadSnapshotCmdBound(workdir, baseRef, workspaceID string, epoch uint64, identity string, binding uint64) tea.Cmd

LoadSnapshotCmdBound is LoadSnapshotCmdAt with a per-view request identity.

func LoadWorkingTreeFileDiff added in v1.12.0

func LoadWorkingTreeFileDiff(ctx context.Context, workdir, path string) (string, error)

LoadWorkingTreeFileDiff loads one working-tree path's patch: tracked diff against HEAD, or an untracked-file synthetic diff.

func ResolveAdminTargets added in v1.0.0

func ResolveAdminTargets(workdir string, workspaceID string, epoch uint64) tea.Cmd

ResolveAdminTargets returns a command that resolves git's administrative paths for workdir off the update goroutine.

Types

type AdminTargetsMsg added in v1.0.0

type AdminTargetsMsg struct {
	Epoch       uint64
	WorkspaceID string
	WorkDir     string
	Targets     []livewatch.Target
}

AdminTargetsMsg carries the resolved git administrative paths for a worktree.

func (AdminTargetsMsg) GetEpoch added in v1.0.0

func (m AdminTargetsMsg) GetEpoch() uint64

GetEpoch implements the plugin epoch check.

type CommitDetail

type CommitDetail struct {
	Hash         string
	ShortHash    string
	Subject      string
	Files        []CommitFile
	IsMerge      bool
	ParentHashes []string
}

CommitDetail is the file list for the commit under the cursor.

func LoadCommitDetail

func LoadCommitDetail(ctx context.Context, workdir, hash string) (*CommitDetail, error)

LoadCommitDetail fetches %H/%h/parents/subject and the commit's numstat files.

The parent list is not decoration: git show on a merge is a combined diff, and a combined diff for one path is empty for every path that was not a conflict resolution. Without the parents, LoadSelectedCommitFile has nothing to diff against and every file in a merge renders as an empty patch.

func LoadCommitDetailFiltered added in v1.16.0

func LoadCommitDetailFiltered(ctx context.Context, workdir, hash string, filter *ReadFilter) (*CommitDetail, error)

LoadCommitDetailFiltered omits protected API paths from the commit file list.

type CommitDetailMsg

type CommitDetailMsg struct {
	Epoch       uint64
	Binding     uint64
	WorkspaceID string
	Identity    string
	Hash        string
	Commit      *CommitDetail
	Err         error
	Revision    string
	NotModified bool
}

CommitDetailMsg is the result of LoadSelectedCommit.

type CommitFile

type CommitFile struct {
	Path      string
	Status    string
	Additions int
	Deletions int
}

CommitFile is one path inside a commit.

type CommitFileDiffMsg added in v1.0.0

type CommitFileDiffMsg struct {
	Truncated   bool
	Epoch       uint64
	Binding     uint64
	WorkspaceID string
	Identity    string
	CommitHash  string
	FilePath    string
	Raw         string
	Err         error
}

CommitFileDiffMsg is a completed commit-file patch load.

type CommitInfo

type CommitInfo struct {
	Hash    string
	Subject string
	Pushed  bool
	Merged  bool
}

CommitInfo is one row in the Diff tab commit list. Hash is git %h.

type CommitResult added in v1.12.0

type CommitResult struct {
	Commit      *CommitDetail
	Revision    string
	NotModified bool
}

CommitResult is one commit-detail load.

type File

type File struct {
	Path      string
	Raw       string
	Additions int
	Deletions int
}

File is one working-tree path in the Diff tab list.

func ParseFiles

func ParseFiles(raw string) []File

ParseFiles splits a unified multi-file diff into named file entries.

type FileResult added in v1.12.0

type FileResult struct {
	Truncated   bool
	Path        string
	Raw         string
	Revision    string
	NotModified bool
}

FileResult is one selected-file patch load.

type Focus

type Focus int

Focus is which sub-pane of the Diff tab is active.

const (
	FocusFileList Focus = iota
	FocusDiff
	FocusCommitFiles
	FocusCommitDiff
)

type Group added in v1.0.0

type Group struct {
	tabs.Group[*View]
}

Group is one Diff leaf's open targets. The pane tree points at this, not at one View. Key = Target.Identity().

func (Group) ActiveView added in v1.0.0

func (g Group) ActiveView() *View

ActiveView is the selected Diff view, or nil.

func (Group) Find added in v1.0.0

func (g Group) Find(id string) int

Find returns the first tab whose key is the target identity, or -1.

func (*Group) OpenOrFocus added in v1.0.0

func (g *Group) OpenOrFocus(t Target, view *View) (index int, created bool)

OpenOrFocus selects the tab for t, or appends view and selects it. An empty Identity is a no-op.

type Hit added in v1.0.0

type Hit struct {
	ID   string
	Rect mouse.Rect
	Data any
}

Hit is one mouse target inside the leaf box. The host registers it.

type LoadState

type LoadState int

LoadState is the snapshot / view load lifecycle.

const (
	LoadStateUnknown LoadState = iota
	LoadStateLoading
	LoadStateClean
	LoadStateReady
	LoadStateTruncated
	LoadStateError
)

type Loader added in v1.12.0

type Loader interface {
	LoadSnapshot(ctx context.Context, workdir, baseRef, ifRevision string) (SnapshotResult, error)
	LoadCommitDetail(ctx context.Context, workdir, hash, ifRevision string) (CommitResult, error)
	LoadRange(ctx context.Context, workdir string, t Target, ifRevision string) (RangeResult, error)
	LoadCommitFile(ctx context.Context, workdir, hash, path, parentHash, ifRevision string) (FileResult, error)
	LoadWorkingTreeFile(ctx context.Context, workdir, path, ifRevision string) (FileResult, error)
}

Loader is the git operations a View issues. A nil Loader uses the package-level local git functions. Injected loaders must not teach View about SSH, JSON, or HostID.

type Patch added in v1.16.0

type Patch struct {
	Raw       string
	Truncated bool
}

Patch is a bounded prefix. Truncated means the total size is unknown.

func GitOutputBounded added in v1.16.0

func GitOutputBounded(ctx context.Context, dir string, limit int64, args ...string) (Patch, error)

GitOutputBounded reads only limit+1 stdout bytes, then stops and reaps git. Stderr is drained separately into a bounded buffer, never into the patch.

func LoadCommitFilePatch added in v1.16.0

func LoadCommitFilePatch(ctx context.Context, workdir, hash, path, parentHash string) (Patch, error)

LoadCommitFilePatch loads a bounded commit patch with explicit truncation.

func LoadCommitFilePatchFiltered added in v1.16.0

func LoadCommitFilePatchFiltered(ctx context.Context, workdir, hash, path, parentHash string, filter *ReadFilter) (Patch, error)

LoadCommitFilePatchFiltered applies policy to a literal selected path.

func LoadRangePatch added in v1.16.0

func LoadRangePatch(ctx context.Context, workdir string, t Target) (Patch, error)

LoadRangePatch preserves the truncation flag for headless consumers.

func LoadRangePatchFiltered added in v1.16.0

func LoadRangePatchFiltered(ctx context.Context, workdir string, t Target, filter *ReadFilter) (Patch, error)

LoadRangePatchFiltered excludes protected API paths before Git emits them.

func LoadWorkingTreeFilePatch added in v1.16.0

func LoadWorkingTreeFilePatch(ctx context.Context, workdir, path string) (Patch, error)

LoadWorkingTreeFilePatch loads a bounded tracked or synthetic untracked patch.

func LoadWorkingTreeFilePatchFiltered added in v1.16.0

func LoadWorkingTreeFilePatchFiltered(ctx context.Context, workdir, path string, filter *ReadFilter) (Patch, error)

LoadWorkingTreeFilePatchFiltered applies policy even to directory selectors.

type RangeMsg added in v1.0.0

type RangeMsg struct {
	Truncated   bool
	Epoch       uint64
	Binding     uint64
	WorkspaceID string
	Identity    string
	Raw         string
	Files       []File
	Err         error
	Revision    string
	NotModified bool
}

RangeMsg is the result of LoadRange for one A..B / A...B tab.

type RangeResult added in v1.12.0

type RangeResult struct {
	Truncated   bool
	Raw         string
	Files       []File
	Revision    string
	NotModified bool
}

RangeResult is one A..B / A...B patch load.

type ReadFilter added in v1.16.0

type ReadFilter struct {
	// ExcludePaths are Git-ready exclusion pathspecs, including any magic flags.
	ExcludePaths []string
	// AllowPath runs before an untracked path is inspected or opened.
	AllowPath func(string) bool
}

ReadFilter narrows an API diff before Git or an untracked-file reader emits its contents. A nil filter preserves the desktop's ordinary Git view.

type RenderOpts

type RenderOpts struct {
	Hit          func(id string, x, y, w, h int, data any)
	ContentBaseX int
	BaseY        int
	PanelHeight  int
	Truncate     func(string, int, string) string
	// PaintFile draws one file body. workspacediff cannot import gitstatus;
	// the project host supplies RenderLineDiff / RenderSideBySide /
	// RenderFullFileSideBySide here. Empty return falls back to renderRaw.
	PaintFile func(name, raw string, mode ViewMode, width, height, scroll, horiz int) string
	// Handle is the list/hunk divider's hover/drag state.
	Handle ui.HandleState
}

RenderOpts controls optional chrome the project plugin needs and the global preview does not: hit regions, list-pane width, host paint.

type Scope

type Scope int

Scope names the three distinct questions answered by the Diff pane.

const (
	ScopeWorkingTree Scope = iota
	ScopeCommits
	ScopeAggregate
)

func ParseScope added in v1.0.0

func ParseScope(s string) Scope

ParseScope reads a persisted scope. Unknown values are working-tree.

func (Scope) Persist added in v1.0.0

func (s Scope) Persist() string

Persist is the state.json spelling of a working-tree scope.

type Snapshot

type Snapshot struct {
	State                 LoadState
	WorkingTree           string
	Files                 []File
	Commits               []CommitInfo
	AggregateCommitted    string
	AggregateUncommitted  string
	BaseRef               string
	MergeBase             string
	UntrackedShown        int
	UntrackedOmitted      int
	UntrackedBytesOmitted int64
	Truncated             bool
}

Snapshot is the three explicit diff views resolved from one worktree/base identity.

func LoadSnapshot

func LoadSnapshot(ctx context.Context, workdir, baseRef string) (*Snapshot, error)

LoadSnapshot resolves base and HEAD, then loads the pinned snapshot.

func LoadSnapshotFiltered added in v1.16.0

func LoadSnapshotFiltered(ctx context.Context, workdir, baseRef string, filter *ReadFilter) (*Snapshot, error)

LoadSnapshotFiltered applies an optional API policy before reading patches.

func LoadSnapshotPinned

func LoadSnapshotPinned(ctx context.Context, workdir, baseRef, baseOID, headOID string) (*Snapshot, error)

LoadSnapshotPinned loads working-tree, unique commits, and aggregate diffs against already-resolved OIDs.

type SnapshotMsg

type SnapshotMsg struct {
	Epoch       uint64
	Binding     uint64
	WorkspaceID string
	Identity    string
	Snapshot    *Snapshot
	Err         error
	Command     string
	BaseRef     string

	// Refresh marks a snapshot produced by View.Refresh rather than an explicit
	// load: it preserves the selected file and scroll offset, and is discarded
	// when the repository state came back unchanged. See live.go.
	Refresh     bool
	Revision    string
	NotModified bool
}

SnapshotMsg is a completed snapshot load for one worktree.

type SnapshotResult added in v1.12.0

type SnapshotResult struct {
	Snapshot    *Snapshot
	Revision    string
	NotModified bool
}

SnapshotResult is one working-tree snapshot load.

type Target added in v1.0.0

type Target struct {
	Kind TargetKind
	A    string // resolved left rev; empty for working-tree
	B    string // resolved right rev for ranges
	Dots string // ".." or "..." for ranges; empty otherwise
	Path string // optional file to select once the load lands
}

Target is the spec a Diff tab or leaf is showing.

func MustParse added in v1.0.0

func MustParse(raw string) Target

MustParse is ParseSpec that panics on refusal. Tests and fixtures only.

func ParseSpec added in v1.0.0

func ParseSpec(raw string) (Target, bool)

ParseSpec accepts user-facing forms and Identity forms.

func ResolveSpec added in v1.0.0

func ResolveSpec(ctx context.Context, workdir string, t Target) (Target, error)

ResolveSpec runs git rev-parse in workdir and fills A/B with object names. Working-tree targets are returned unchanged.

func WorkingTreeTarget added in v1.0.0

func WorkingTreeTarget() Target

WorkingTreeTarget is the Diff tab's working-tree view.

func (Target) Identity added in v1.0.0

func (t Target) Identity() string

Identity is the stable tab key and the only string that crosses the request bus.

func (Target) TabLabel added in v1.0.0

func (t Target) TabLabel() string

TabLabel is the short header label for this target.

type TargetKind added in v1.0.0

type TargetKind int

TargetKind is which git object a Diff view is showing.

const (
	// TargetWorkingTree is git diff HEAD + untracked. Identity is "wt".
	TargetWorkingTree TargetKind = iota
	// TargetCommit is one commit as the root view.
	TargetCommit
	// TargetRange is git diff A..B or A...B.
	TargetRange
)

type View

type View struct {
	Snapshot *Snapshot
	State    LoadState
	Error    string
	Scope    Scope

	Content string
	Raw     string
	Files   []File
	Commits []CommitInfo

	Cursor      int
	Scroll      int
	DiffScroll  int
	HorizScroll int
	Focus       Focus
	ViewMode    ViewMode

	CommitDetail            *CommitDetail
	CommitFileCursor        int
	CommitFileScroll        int
	CommitFileDiffRaw       string
	CommitFileDiffTruncated bool

	// CommitDetailErr is why the commit under the cursor has no file list.
	// A load that fails must say so: a nil CommitDetail with nothing recorded
	// is indistinguishable from a load still in flight, and the pane sat on
	// "Loading commit files…" forever.
	CommitDetailErr string
	// CommitFileDiffLoaded reports that a commit-file patch load has landed,
	// empty or not. CommitFileDiffErr is why it failed. Together they separate
	// "still loading" from "loaded and there is nothing to show".
	CommitFileDiffLoaded bool
	CommitFileDiffErr    string

	Target      Target
	Epoch       uint64
	Binding     uint64
	WorkspaceID string
	WorkDir     string
	Revision    string

	// Loader issues git operations. Nil uses local git in this process.
	Loader Loader

	// Host paint/load hooks. workspacediff cannot import gitstatus; the
	// project plugin fills these so CycleViewMode, n/N, and paging work.
	LoadFullFile     func() tea.Cmd
	JumpChange       func(scroll int, prev bool) int
	PaintedLineCount func() int
	LeavingFullFile  func(scroll int) int
	ClearPaintedFile func()

	// HasFilePicker is set by a host that answers "f" with a file picker. The
	// global preview does not, and must not advertise a key nothing answers.
	HasFilePicker bool
	// contains filtered or unexported fields
}

View is the reusable Diff pane model: one snapshot, one cursor, one commit detail. The project plugin wraps it; the global preview holds one for the selected worktree.

func (*View) AbandonSelection added in v1.14.0

func (v *View) AbandonSelection() textselect.Result

AbandonSelection ends a gesture whose release never arrived.

func (*View) ApplyCommitDetail

func (v *View) ApplyCommitDetail(msg CommitDetailMsg) tea.Cmd

ApplyCommitDetail installs a loaded commit if it is still the row under the cursor, or the root of a TargetCommit tab whose Identity matches.

func (*View) ApplyCommitFileDiff added in v1.0.0

func (v *View) ApplyCommitFileDiff(msg CommitFileDiffMsg) tea.Cmd

ApplyCommitFileDiff installs a commit file patch if the cursor still matches.

func (*View) ApplyListWidthDelta added in v1.0.0

func (v *View) ApplyListWidthDelta(dx, leafWidth int) int

ApplyListWidthDelta adds dx to the current (or default) list width and clamps to min 20 / max leafWidth-30. Hosts that drag from a frozen start should SetListWidth(start) before each call with the total dx from that start.

func (*View) ApplyLoadedSnapshot

func (v *View) ApplyLoadedSnapshot(snapshot *Snapshot, workdir, workspaceID string) tea.Cmd

ApplyLoadedSnapshot installs a snapshot, applies the default working-tree scope, and loads the commit under the cursor if that is the current item.

func (*View) ApplyRangeMsg added in v1.0.0

func (v *View) ApplyRangeMsg(msg RangeMsg) tea.Cmd

ApplyRangeMsg installs a range patch when Identity matches this r: tab.

func (*View) ApplySnapshot

func (v *View) ApplySnapshot()

ApplySnapshot rebuilds the working-tree / commits lists from the snapshot and clamps the cursor. It does not load commit detail; callers that just applied a snapshot should also call LoadSelectedCommit.

func (*View) ApplySnapshotMsg added in v1.0.0

func (v *View) ApplySnapshotMsg(msg SnapshotMsg, workdir, workspaceID string) tea.Cmd

ApplySnapshotMsg installs a loaded snapshot or records the error, dropping stale msgs.

func (*View) ApplyWorkingTreeFile added in v1.12.0

func (v *View) ApplyWorkingTreeFile(msg WorkingTreeFileMsg) tea.Cmd

ApplyWorkingTreeFile installs a working-tree file patch if the cursor still matches.

func (*View) Bind added in v1.0.0

func (v *View) Bind(workdir, workspaceID string, epoch uint64)

Bind records the host identity used to drop stale async results.

func (*View) BindGeneration added in v1.2.0

func (v *View) BindGeneration(workdir, workspaceID string, epoch, binding uint64)

BindGeneration adds a per-view request identity. Legacy hosts use zero; shared decks use their never-reused tab ID so raw broadcasts cannot cross a context rebind that deliberately reuses workspace and epoch.

func (*View) ClampCursor

func (v *View) ClampCursor()

ClampCursor keeps the cursor inside the current item list.

func (*View) ClampScroll added in v1.0.0

func (v *View) ClampScroll()

ClampScroll keeps list and content offsets inside the allocated box. Call from HandleKey, ApplySnapshot, and SetSize — never while painting.

func (*View) ClearSelection added in v1.14.0

func (v *View) ClearSelection()

ClearSelection drops the selection and any gesture editing it.

func (*View) Commands added in v1.0.0

func (v *View) Commands(context string) []plugin.Command

Commands are the short footer names for a focused Diff surface.

Every key HandleKey answers is named here, and every one of them has a matching row in internal/keymap/bindings.go for both Diff contexts. The bindings are what put the keys in the footer, the help sheet and the command palette; before they existed, moving around a diff was folklore.

The set follows the focused sub-pane, because the same key means different things in each: on the list l opens, in the diff body it scrolls sideways.

func (*View) ContentMaxScroll added in v1.0.0

func (v *View) ContentMaxScroll(height int) int

ContentMaxScroll returns the exact vertical bound for the content currently rendered in the right pane (or collapsed view).

func (*View) CycleScope added in v1.0.0

func (v *View) CycleScope() tea.Cmd

CycleScope walks working-tree → commits → aggregate. No-op on commit/range targets.

func (*View) CycleViewMode added in v1.0.0

func (v *View) CycleViewMode() tea.Cmd

CycleViewMode walks unified → side-by-side → full-file. Entering full-file returns the host LoadFullFile cmd.

func (*View) DividerHit added in v1.0.0

func (v *View) DividerHit(leaf mouse.Rect) mouse.Rect

DividerHit is the 3-col drag target on the list/diff split, inside the leaf box only. Empty when the layout is collapsed or the box is too narrow.

func (*View) EffectiveListWidth added in v1.0.0

func (v *View) EffectiveListWidth(leafWidth int) int

EffectiveListWidth is the width the divider would use for this leaf. The argument is the leaf box's width; the padding is taken off here so callers hold one meaning of "width" and the drag lands on the drawn divider.

func (*View) FileCount

func (v *View) FileCount() int

FileCount is the number of working-tree files in the current scope.

func (*View) FileHits added in v1.0.0

func (v *View) FileHits(leaf mouse.Rect) []Hit

FileHits are the file/commit/pane targets inside the leaf. Collapsed mode still reports the visible list or pane. The host registers these.

func (*View) FileNames added in v1.0.0

func (v *View) FileNames() []string

FileNames is the working-tree list for the host file picker.

func (*View) HandleClick added in v1.1.0

func (v *View) HandleClick(id string, data any) tea.Cmd

HandleClick applies a single click on an inner Diff hit. The host still owns leaf focus and drag-start; this mutates only the view.

func (*View) HandleDoubleClick added in v1.1.0

func (v *View) HandleDoubleClick(id string, data any) tea.Cmd

HandleDoubleClick drills into the hit: a file opens its hunks, a commit opens its file list, a commit file opens its patch.

func (*View) HandleKey added in v1.0.0

func (v *View) HandleKey(msg tea.KeyPressMsg) (tea.Cmd, bool)

HandleKey applies a Diff-tab key. handled is false when the host should keep the key (h/left on the file list, unknown keys).

func (*View) HandleSelectionKey added in v1.14.0

func (v *View) HandleSelectionKey(msg tea.KeyMsg) textselect.Result

HandleSelectionKey answers the chords that act on the selection: copy, select-all, and escape.

func (*View) HandleSelectionMouse added in v1.14.0

func (v *View) HandleSelectionMouse(action mouse.MouseAction) textselect.Result

HandleSelectionMouse advances the gesture over the pane and reports what the host owes for it. AutoScroll is dropped rather than applied: see the note at the top of this file.

func (*View) HandleWheel added in v1.1.0

func (v *View) HandleWheel(id string, delta int) tea.Cmd

HandleWheel scrolls the list or body that owns id. File-list notches only move the cursor; they do not kick off a commit load.

func (*View) HasSelection added in v1.14.0

func (v *View) HasSelection() bool

HasSelection reports whether anything in this pane is selected.

func (*View) Height added in v1.0.0

func (v *View) Height() int

func (*View) JumpFile added in v1.0.0

func (v *View) JumpFile(delta int) tea.Cmd

JumpFile moves to the next or previous file in this tab's list.

func (*View) ListWidth

func (v *View) ListWidth() int

ListWidth is the persisted file-list width. Zero means "use the default 25%".

func (*View) LoadCommit added in v1.0.0

func (v *View) LoadCommit(hash string) tea.Cmd

LoadCommit fetches one commit's file list, tagged for stale-drop.

func (*View) LoadRange added in v1.0.0

func (v *View) LoadRange() tea.Cmd

LoadRange fetches git diff --binary A..B or A...B for this tab.

func (*View) LoadSelectedCommit

func (v *View) LoadSelectedCommit(workdir, workspaceID string) tea.Cmd

LoadSelectedCommit loads the commit under the cursor. Snapshot/scope populate can leave the cursor on a commit without a move, so this does not require a cursor-change event. Skip if that commit is already loaded.

func (*View) LoadSelectedCommitFile added in v1.0.0

func (v *View) LoadSelectedCommitFile() tea.Cmd

LoadSelectedCommitFile loads the patch for the commit file under the cursor.

func (*View) LoadSelectedWorkingTreeFile added in v1.12.0

func (v *View) LoadSelectedWorkingTreeFile() tea.Cmd

LoadSelectedWorkingTreeFile loads a working-tree file whose patch was omitted.

func (*View) LoadSnapshotCmd added in v1.12.0

func (v *View) LoadSnapshotCmd(baseRef string, refresh bool) tea.Cmd

LoadSnapshotCmd is this view's working-tree load, using Loader when set.

func (*View) Observe added in v1.0.0

func (v *View) Observe()

Observe records that the repository may have moved.

A view that can never re-read declines to be owed one. A commit or range diff is immutable, and a view that has not loaded is owned by the host's own load path — for either, View.Refresh refuses before it reaches the refresher, so accepting the change here would leave a dirty flag nothing can ever clear. That matters because a host asks whether a refresh is owed in order to retry it: a permanently owed re-read is a permanent retry, which for this view is half a dozen git subprocesses on every update.

func (*View) OnCursorChanged added in v1.0.0

func (v *View) OnCursorChanged(oldCursor int) tea.Cmd

OnCursorChanged resets the right pane after a file-list move.

func (*View) PageSize added in v1.0.0

func (v *View) PageSize() int

PageSize is the height-aware page step: max(1, allocatedHeight/2).

func (*View) Refresh added in v1.0.0

func (v *View) Refresh(workdir, baseRef, workspaceID string, suppressed bool) tea.Cmd

Refresh returns a command that re-runs this view's diff, or nil when no re-read is owed.

Only working-tree targets refresh. A commit and a range diff are immutable once written: `c:abc123` renders the same bytes forever, so re-running it would spend six subprocesses to produce the content already on screen. They are still worth watching, because the same watcher serves every tab in a pane, but they never re-read.

func (*View) RefreshPending added in v1.0.0

func (v *View) RefreshPending() bool

RefreshPending reports whether a re-read is owed but has not started.

func (*View) Render

func (v *View) Render(width, height int, opts RenderOpts) string

Render draws the working-tree + commits Diff view.

The body is inset by ContentInset columns on both sides, the same single column the issue pane keeps, so the Diff leaf does not sit flush against its neighbour's border. The inset is applied here and in ContentBox alone: every piece of column arithmetic below — the list/diff divider, the minimap, the side-by-side split, and the hit regions the host registers — works in the inner box, so what is drawn and what is clickable cannot drift apart.

func (*View) ScrollAtBoundary added in v1.0.0

func (v *View) ScrollAtBoundary(delta, height int) bool

ScrollAtBoundary reports whether delta points farther past the rendered content boundary.

func (*View) ScrollContent

func (v *View) ScrollContent(delta, height int)

ScrollContent moves the visible right-pane (or collapsed) content.

func (*View) SelectedCommit

func (v *View) SelectedCommit() (CommitInfo, bool)

SelectedCommit is the commit under the cursor, if any.

func (*View) SelectedFileName added in v1.0.0

func (v *View) SelectedFileName() string

SelectedFileName is the working-tree path under the cursor, if any.

func (*View) SelectionCopyCmd added in v1.14.0

func (v *View) SelectionCopyCmd(result textselect.Result, wrap func(textselect.CopyNotice) tea.Msg) tea.Cmd

SelectionCopyCmd delivers the copy an engine result asked for, phrased by the shared pipeline and wrapped in whatever notification type the host uses.

func (*View) SelectionText added in v1.14.0

func (v *View) SelectionText() []string

SelectionText is the selection as the user sees it: the rows it covers, without the styling they were drawn with.

func (*View) SetListWidth added in v1.0.0

func (v *View) SetListWidth(w int)

SetListWidth stores a persisted or drag-start width. Zero restores the default.

func (*View) SetOrigin added in v1.14.0

func (v *View) SetOrigin(x, y int)

SetOrigin records where the host last drew this pane's body, in the coordinate space its mouse events arrive in. A pane that has not been drawn has no origin, so it hit-tests as empty rather than as the top-left corner of the screen.

func (*View) SetSelection added in v1.14.0

func (v *View) SetSelection(keys textselect.Keys, copyOnSelect bool)

SetSelection binds the host's shared selection settings: the chords the pane answers, and whether finishing a drag copies without being asked.

func (*View) SetSize added in v1.0.0

func (v *View) SetSize(width, height int)

SetSize records the allocated leaf box and reclamps scroll. It must not persist a clamped listWidth: hosts call this from View() every frame, and a shrink must not forget the user-dragged width.

func (*View) TotalItems

func (v *View) TotalItems() int

TotalItems is files + commits, the navigable left-pane length.

func (*View) WatchTargets added in v1.0.0

func (v *View) WatchTargets(workdir string, admin []livewatch.Target) []livewatch.Target

WatchTargets returns everything worth watching for this view: git's administrative files plus the files currently under review and the directories holding them.

admin is the result of ResolveAdminTargets for the view's worktree, passed in rather than resolved here because resolving it runs git and this is called from the update loop every time the file list changes.

func (*View) WheelAtBoundary added in v1.1.0

func (v *View) WheelAtBoundary(id string, delta int) bool

WheelAtBoundary reports whether a notch on id would move past the rendered edge of that inner pane.

func (*View) Width added in v1.0.0

func (v *View) Width() int

Width and Height are the last SetSize allocation.

type ViewMode

type ViewMode int

ViewMode is how a per-file diff is drawn.

const (
	ViewUnified ViewMode = iota
	ViewSideBySide
	ViewFullFile
)

func ParseViewMode added in v1.0.0

func ParseViewMode(s string) ViewMode

ParseViewMode reads a persisted view mode. Unknown values are unified.

func (ViewMode) Persist added in v1.0.0

func (m ViewMode) Persist() string

Persist is the state.json spelling of a view mode.

type WorkingTreeFileMsg added in v1.12.0

type WorkingTreeFileMsg struct {
	Truncated   bool
	Epoch       uint64
	Binding     uint64
	WorkspaceID string
	Identity    string
	Path        string
	Raw         string
	Err         error
}

WorkingTreeFileMsg is a cursor-driven working-tree file patch load.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL