Skip to content

feat(commands): diff the current buffer against its last save - #430

Merged
barrettruth merged 1 commit into
mainfrom
feat/diff-files-buffer-last-save
Aug 14, 2026
Merged

feat(commands): diff the current buffer against its last save#430
barrettruth merged 1 commit into
mainfrom
feat/diff-files-buffer-last-save

Conversation

@barrettruth

Copy link
Copy Markdown
Owner

Problem

:Diff files {left} is documented as taking the current buffer as its new side, and that is how it was described when the subcommand was added, but the implementation resolves that buffer to its name and then reads the name back from disk. Both sides of a single-path invocation are therefore disk reads: unsaved changes are invisible, and naming the current file compares it to itself and always reports no changes. That also contradicts the claim that the form mirrors :Diff {rev}, which does substitute live buffer content for the worktree endpoint. Nothing in the command surface spells "compare this buffer to its last save".

Solution

Apply the rule :Diff already follows to :Diff files: a named path is read from disk, and a side the user did not name is the current buffer. The new side of a single-path invocation becomes the buffer's live content, and a bare :Diff files also defaults the old side to that buffer's file on disk, so it compares the buffer to its last save. Two named paths behave exactly as before.

A buffer-backed side reads as buffer:{name} in the view name, the list title, and messages, while the diff header keeps real paths so hunk and path parsing are untouched. The files source records the buffer it was opened against, so reloading the view re-reads that buffer instead of quietly reverting to disk, and falls back to the path once the buffer is gone. Difftastic takes the content-based span maps for a buffer-backed side, since the path-based ones can only see disk, and a named buffer that has never been written is no longer refused as unreadable.

Closes #429.

@barrettruth
barrettruth merged commit f425d9e into main Aug 14, 2026
5 checks passed
@barrettruth
barrettruth deleted the feat/diff-files-buffer-last-save branch August 14, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: compare buffer against last save

1 participant