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
- func CommitDetailMatchesListHash(detail *CommitDetail, listHash string) bool
- func ContentBox(leaf mouse.Rect) mouse.Rect
- func DetectDefaultBranch(ctx context.Context, workdir string) string
- func IsBodyRegion(id string) bool
- func LoadRangeCmd(workdir string, t Target, epoch uint64, workspaceID string) tea.Cmd
- func LoadSnapshotCmd(workdir, baseRef, workspaceID string) tea.Cmd
- func LoadSnapshotCmdAt(workdir, baseRef, workspaceID string, epoch uint64, identity string) tea.Cmd
- func LoadSnapshotCmdBound(workdir, baseRef, workspaceID string, epoch uint64, identity string, ...) tea.Cmd
- func ResolveAdminTargets(workdir string, workspaceID string, epoch uint64) tea.Cmd
- type AdminTargetsMsg
- type CommitDetail
- type CommitDetailMsg
- type CommitFile
- type CommitFileDiffMsg
- type CommitInfo
- type File
- type Focus
- type Group
- type Hit
- type LoadState
- type RangeMsg
- type RenderOpts
- type Scope
- type Snapshot
- type SnapshotMsg
- type Target
- type TargetKind
- type View
- func (v *View) ApplyCommitDetail(msg CommitDetailMsg) tea.Cmd
- func (v *View) ApplyCommitFileDiff(msg CommitFileDiffMsg) tea.Cmd
- func (v *View) ApplyListWidthDelta(dx, leafWidth int) int
- func (v *View) ApplyLoadedSnapshot(snapshot *Snapshot, workdir, workspaceID string) tea.Cmd
- func (v *View) ApplyRangeMsg(msg RangeMsg) tea.Cmd
- func (v *View) ApplySnapshot()
- func (v *View) ApplySnapshotMsg(msg SnapshotMsg, workdir, workspaceID string) tea.Cmd
- func (v *View) Bind(workdir, workspaceID string, epoch uint64)
- func (v *View) BindGeneration(workdir, workspaceID string, epoch, binding uint64)
- func (v *View) ClampCursor()
- func (v *View) ClampScroll()
- func (v *View) Commands(context string) []plugin.Command
- func (v *View) ContentMaxScroll(height int) int
- func (v *View) CycleScope() tea.Cmd
- func (v *View) CycleViewMode() tea.Cmd
- func (v *View) DividerHit(leaf mouse.Rect) mouse.Rect
- func (v *View) EffectiveListWidth(leafWidth int) int
- func (v *View) FileCount() int
- func (v *View) FileHits(leaf mouse.Rect) []Hit
- func (v *View) FileNames() []string
- func (v *View) HandleClick(id string, data any) tea.Cmd
- func (v *View) HandleDoubleClick(id string, data any) tea.Cmd
- func (v *View) HandleKey(msg tea.KeyPressMsg) (tea.Cmd, bool)
- func (v *View) HandleWheel(id string, delta int) tea.Cmd
- func (v *View) Height() int
- func (v *View) JumpFile(delta int) tea.Cmd
- func (v *View) ListWidth() int
- func (v *View) LoadCommit(hash string) tea.Cmd
- func (v *View) LoadRange() tea.Cmd
- func (v *View) LoadSelectedCommit(workdir, workspaceID string) tea.Cmd
- func (v *View) LoadSelectedCommitFile() tea.Cmd
- func (v *View) Observe()
- func (v *View) OnCursorChanged(oldCursor int) tea.Cmd
- func (v *View) PageSize() int
- func (v *View) Refresh(workdir, baseRef, workspaceID string, suppressed bool) tea.Cmd
- func (v *View) RefreshPending() bool
- func (v *View) Render(width, height int, opts RenderOpts) string
- func (v *View) ScrollAtBoundary(delta, height int) bool
- func (v *View) ScrollContent(delta, height int)
- func (v *View) SelectedCommit() (CommitInfo, bool)
- func (v *View) SelectedFileName() string
- func (v *View) SetListWidth(w int)
- func (v *View) SetSize(width, height int)
- func (v *View) TotalItems() int
- func (v *View) WatchTargets(workdir string, admin []livewatch.Target) []livewatch.Target
- func (v *View) WheelAtBoundary(id string, delta int) bool
- func (v *View) Width() int
- type ViewMode
Constants ¶
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" )
const ( MaxUntrackedFileSize = 1 << 20 MaxUntrackedFiles = 50 MaxUntrackedTotalBytes = 4 << 20 )
const CollapseThreshold = 120
CollapseThreshold is the minimum width for the two-pane Diff layout.
const ( // ContentInset is the columns of padding the Diff body keeps on each side, // matching the issue pane's horizontal content padding. ContentInset = 1 )
const IdentityWorkingTree = "wt"
IdentityWorkingTree is TargetWorkingTree.Identity(). Never "HEAD".
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
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 ¶
DetectDefaultBranch finds the repo's default branch (remote HEAD, then main/master).
func IsBodyRegion ¶ added in v1.1.0
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 LoadRangeCmd ¶ added in v1.0.0
LoadRangeCmd runs one git diff for a range target.
func LoadSnapshotCmd ¶
LoadSnapshotCmd loads a snapshot for workdir and tags it with workspaceID.
func LoadSnapshotCmdAt ¶ added in v1.0.0
LoadSnapshotCmdAt is LoadSnapshotCmd with epoch and target identity.
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.
type CommitDetailMsg ¶
type CommitDetailMsg struct {
Epoch uint64
Binding uint64
WorkspaceID string
Identity string
Hash string
Commit *CommitDetail
Err error
}
CommitDetailMsg is the result of LoadSelectedCommit.
type CommitFile ¶
CommitFile is one path inside a commit.
type CommitFileDiffMsg ¶ added in v1.0.0
type CommitFileDiffMsg struct {
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 ¶
CommitInfo is one row in the Diff tab commit list. Hash is git %h.
type File ¶
File is one working-tree path in the Diff tab list.
func ParseFiles ¶
ParseFiles splits a unified multi-file diff into named file entries.
type Group ¶ added in v1.0.0
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
ActiveView is the selected Diff view, or nil.
type RangeMsg ¶ added in v1.0.0
type RangeMsg struct {
Epoch uint64
Binding uint64
WorkspaceID string
Identity string
Raw string
Files []File
Err error
}
RangeMsg is the result of LoadRange for one A..B / A...B tab.
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.
func ParseScope ¶ added in v1.0.0
ParseScope reads a persisted scope. Unknown values are working-tree.
type Snapshot ¶
type Snapshot struct {
State LoadState
WorkingTree string
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 ¶
LoadSnapshot resolves base and HEAD, then loads the pinned snapshot.
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
}
SnapshotMsg is a completed snapshot load for one worktree.
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
MustParse is ParseSpec that panics on refusal. Tests and fixtures only.
func ResolveSpec ¶ added in v1.0.0
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.
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
// 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
// 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) 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
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 ¶
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
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) Bind ¶ added in v1.0.0
Bind records the host identity used to drop stale async results.
func (*View) BindGeneration ¶ added in v1.2.0
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) Commands ¶ added in v1.0.0
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
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
CycleScope walks working-tree → commits → aggregate. No-op on commit/range targets.
func (*View) CycleViewMode ¶ added in v1.0.0
CycleViewMode walks unified → side-by-side → full-file. Entering full-file returns the host LoadFullFile cmd.
func (*View) DividerHit ¶ added in v1.0.0
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
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) FileHits ¶ added in v1.0.0
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
FileNames is the working-tree list for the host file picker.
func (*View) HandleClick ¶ added in v1.1.0
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
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
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) HandleWheel ¶ added in v1.1.0
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) JumpFile ¶ added in v1.0.0
JumpFile moves to the next or previous file in this tab's list.
func (*View) ListWidth ¶
ListWidth is the persisted file-list width. Zero means "use the default 25%".
func (*View) LoadCommit ¶ added in v1.0.0
LoadCommit fetches one commit's file list, tagged for stale-drop.
func (*View) LoadRange ¶ added in v1.0.0
LoadRange fetches git diff --binary A..B or A...B for this tab.
func (*View) LoadSelectedCommit ¶
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
LoadSelectedCommitFile loads the patch for the commit file under the cursor.
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
OnCursorChanged resets the right pane after a file-list move.
func (*View) PageSize ¶ added in v1.0.0
PageSize is the height-aware page step: max(1, allocatedHeight/2).
func (*View) Refresh ¶ added in v1.0.0
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
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
ScrollAtBoundary reports whether delta points farther past the rendered content boundary.
func (*View) ScrollContent ¶
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
SelectedFileName is the working-tree path under the cursor, if any.
func (*View) SetListWidth ¶ added in v1.0.0
SetListWidth stores a persisted or drag-start width. Zero restores the default.
func (*View) SetSize ¶ added in v1.0.0
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 ¶
TotalItems is files + commits, the navigable left-pane length.
func (*View) WatchTargets ¶ added in v1.0.0
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
WheelAtBoundary reports whether a notch on id would move past the rendered edge of that inner pane.
type ViewMode ¶
type ViewMode int
ViewMode is how a per-file diff is drawn.
func ParseViewMode ¶ added in v1.0.0
ParseViewMode reads a persisted view mode. Unknown values are unified.