Skip to content

feat: inline edit for local diffs - #32

Open
imfing wants to merge 1 commit into
mainfrom
feat/inline-edit
Open

imfing wants to merge 1 commit into
mainfrom
feat/inline-edit

Conversation

@imfing

@imfing imfing commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Summary

Adds an inline edit experience for local (working-tree) diffs, built on the @pierre/diffs 1.4 edit-session API:

  • Edit file in the file actions menu starts an edit session on that diff (local mode only — PR/branch diffs review committed states and stay read-only; deleted files excluded)
  • The file header swaps to Cancel / Save while editing; Save accepts the session and writes the completed new-file contents to disk via a new PUT /api/worktree-file endpoint, Cancel rejects and restores the original diff
  • The existing file watcher picks up the write and reloads the diff automatically

Implementation notes

  • git::write_worktree_file mirrors read_worktree_file's path validation (safe relative path, canonicalized under the repo root) and only overwrites existing files; contents capped at the blob hydration limit
  • EditProvider + CodeView.onItemEditComplete wire up the 1.4 session lifecycle; edit toggles bump the item version since updateItem ignores same-version records
  • Local-mode loadDiffFiles now reads the new side from the worktree: the index-line oid of a worktree diff is computed on the fly and generally absent from the object database (blob hydration 404'd)
  • Diff reloads (SSE/poll) are deferred while a session is active so a remount can't tear down the editor mid-edit; deferred reloads fire on session end
  • The n/p/m shortcuts are suppressed during an edit — the editor's input lives in shadow DOM, so the document-level handler would otherwise steal those keystrokes (this dropped every "n" typed in early testing)

Test plan

  • pnpm test (oxlint + tsc/vite + cargo test) passes; new Rust test covers write_worktree_file (overwrite, no-create, traversal rejection)
  • Verified end-to-end with headless Chromium against a scratch repo: Edit → type → Save writes to disk and the diff refreshes; Edit → type → Cancel reverts the view and leaves disk untouched

Uses the @pierre/diffs 1.4 edit-session API. Edit file from the file
actions menu starts a session (local diffs only); Save writes the new
file contents back to the worktree via PUT /api/worktree-file, Cancel
reverts. Diff reloads are deferred while a session is active, and the
n/p/m shortcuts are suppressed so they don't steal editor keystrokes.
Local-mode hydration now reads the new side from the worktree, since
the index-line oid of a worktree diff is generally not in the object
database.
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.

1 participant