Skip to content

feat(desktop): add editable Monaco diff view for uncommitted changes - #387

Merged
Kitenite merged 1 commit into
mainfrom
gross-sparrow-df1a99
Dec 17, 2025
Merged

Kitenite merged 1 commit into
mainfrom
gross-sparrow-df1a99

Conversation

@Kitenite

@Kitenite Kitenite commented Dec 17, 2025 •

Copy link
Copy Markdown
Member

Summary

  • Enable editing files directly in the Monaco diff view for unstaged and staged changes
  • Added saveFile tRPC mutation to write file contents to disk
  • Modified side of DiffEditor is now editable with ⌘S / Ctrl+S to save
  • Shows "Editable ⌘S to save" badge in the diff toolbar when editable
  • When saving from staged view, automatically switches to unstaged view (since edits become new unstaged changes)

Test plan

  • Open a workspace with uncommitted changes
  • Select an unstaged file - verify "Editable" badge appears and you can edit the right side
  • Make changes and press ⌘S - verify file saves and diff updates
  • Select a staged file - verify you can also edit it
  • Save changes in staged view - verify it switches to unstaged view showing new changes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added in-place file editing directly in the changes view.
    • Implemented save functionality to persist edited files to disk.
    • Added visual indicators for edit mode and saving status.
    • Introduced keyboard shortcut (Ctrl/Cmd+S) for quick saving.

✏️ Tip: You can customize this high-level summary in your review settings.

Allow editing files directly in the diff view for unstaged and staged changes:
- Added saveFile tRPC mutation to write file contents
- DiffEditor modified side is now editable with Cmd+S to save
- Shows "Editable ⌘S to save" badge in toolbar
- When saving staged files, automatically switches to unstaged view

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 17, 2025 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This PR introduces file-saving functionality to the desktop application. A new TRPC endpoint saveFile writes file content to disk, while the frontend integrates editing capabilities into the diff viewer with keyboard shortcuts and cache invalidation to reflect saved changes.

Changes

Cohort / File(s) Summary
Backend File Persistence
apps/desktop/src/lib/trpc/routers/changes/changes.ts
Added writeFile import and new saveFile TRPC procedure to persist modified file content to disk with UTF-8 encoding and error handling.
Frontend Save Integration
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/ChangesContent.tsx
Integrated saveFile mutation with success callback, added cache invalidation, introduced handleSave handler, computed isEditable state, and wired editing/saving props to child components (DiffViewer, DiffToolbar).
UI Components
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffToolbar/DiffToolbar.tsx, apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx
DiffToolbar now displays editable/saving state badges; DiffViewer added editable mode, onSave callback, Ctrl/Cmd+S keyboard shortcut registration, and dynamic editor readOnly behavior.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChangesContent as ChangesContent<br/>(React Component)
    participant DiffViewer as DiffViewer
    participant Mutation as saveFile<br/>(TRPC Mutation)
    participant Backend as Backend<br/>(File System)
    participant Store as useChangesStore
    participant Utils as TRPC Utils<br/>(Cache)

    User->>DiffViewer: Press Ctrl/Cmd+S to save
    DiffViewer->>DiffViewer: handleSave triggered
    DiffViewer->>ChangesContent: Call onSave(content)
    ChangesContent->>Mutation: Invoke saveFile(worktreePath, filePath, content)
    rect rgb(200, 220, 255)
        Mutation->>Backend: Write content to disk (UTF-8)
        Backend-->>Mutation: Success/Error
    end
    Mutation->>Utils: Invalidate file content cache
    Mutation->>Utils: Invalidate file status cache
    Mutation->>ChangesContent: onSuccess callback triggered
    rect rgb(220, 255, 220)
        ChangesContent->>Store: selectFile(staged → unstaged)
        Store-->>ChangesContent: Updated selection
    end
    ChangesContent->>DiffViewer: Re-render with updated state
    DiffViewer-->>User: Reflect saved changes
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • TRPC endpoint logic: Verify saveFile error handling, path resolution, and file system write safety.
  • Cache invalidation sequencing: Ensure both file content and status caches are properly invalidated to prevent stale views.
  • Editor state management: Review DiffViewer's internal modified editor reference, keyboard shortcut registration/cleanup, and readOnly toggle logic.
  • Store interaction: Confirm selectFile is called correctly and switches view from staged to unstaged after successful save.
  • Mutation side effects: Verify onSuccess callback timing and view state transitions are correct, especially when saving from staged files.

Poem

🐰 A file saved is a worry spared,

With Ctrl+S, the changes squared,

The diff now edits in its place,

And caches clear at saving's pace! ✏️

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch gross-sparrow-df1a99

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 052a462 and 469a3bf.

📒 Files selected for processing (4)
  • apps/desktop/src/lib/trpc/routers/changes/changes.ts (2 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/ChangesContent.tsx (4 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffToolbar/DiffToolbar.tsx (3 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/ChangesContent/components/DiffViewer/DiffViewer.tsx (2 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Kitenite
Kitenite merged commit 361067e into main Dec 17, 2025
10 of 11 checks passed
@Kitenite
Kitenite deleted the gross-sparrow-df1a99 branch December 17, 2025 01:46
@github-actions

github-actions Bot commented Dec 17, 2025 •

Copy link
Copy Markdown
Contributor

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) ✅ View Branch
Vercel API (Vercel) ✅ Open Preview
Vercel Web (Vercel) ✅ Open Preview
Vercel Marketing (Vercel) ✅ Open Preview
Vercel Admin (Vercel) ✅ Open Preview
Vercel Docs (Vercel) ✅ Open Preview

Preview updates automatically with new commits

This branch was previously deployed

1 inactive deployment
preview — 469a3bfa Deployed Dec 17, 2025 by Kitenite via Deploy Docs #321
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