Skip to content

fix: restore proper window layout after diff operations #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alvarosevilla95
Copy link
Contributor

@alvarosevilla95 alvarosevilla95 commented Jun 22, 2025

Summary

  • Fixes window layout disruption after diff operations complete
  • Ensures Claude's terminal maintains proper width ratios (30% default) after diffs

Problem

When Claude creates diff views and the user accepts/rejects changes, the window layout becomes disrupted. The terminal window loses its configured proportions, making the interface less usable.

Solution

Core Fix:

  • Added restore_window_layout() function to intelligently restore terminal window proportions
  • Integrated restoration at all diff completion points (accept, reject, cleanup)
  • Maintains proper terminal width ratios based on user configuration

Technical Implementation

Window Detection

  • Handles both snacks.nvim and native terminal implementations
  • Graceful fallback when terminal windows aren't found

Layout Restoration Process

  1. Find the Claude terminal window among all open windows
  2. Calculate proper terminal width based on user configuration (default 30%)
  3. Apply width settings with window equalization
  4. Re-enforce terminal proportions to prevent drift

Integration Points

  • _resolve_diff_as_saved(): Restore layout after user accepts changes
  • _cleanup_diff_state(): Restore layout during diff cleanup
  • deny_current_diff(): Restore layout when user rejects changes

Files Changed

  • lua/claudecode/diff.lua: Integrated window restoration calls, simplified to delegate to terminal module
  • lua/claudecode/terminal.lua: Added restore_window_layout() function and get_config() method

@alvarosevilla95 alvarosevilla95 force-pushed the fix/diff-window-layout-restoration branch 2 times, most recently from d07440f to 442c2ed Compare June 22, 2025 21:18
@ThomasK33
Copy link
Member

Hey @alvarosevilla95, thanks for this PR.

Could you provide me with steps to reproduce this scrambled layout?

@alvarosevilla95
Copy link
Contributor Author

@ThomasK33 At least for me, this happens when you have Claude propose a diff and you accept / reject it. So:

  • Claude proposes diff, I get split diff view next to claude window
  • Accept diff, split is closed, but now the remaining window and claude are split 50/50, so i need to resize claude back to its original size
Screen.Recording.2025-07-31.at.12.42.41.mov

With this change, after the diff split closes claude preserves its original width.

@alvarosevilla95 alvarosevilla95 force-pushed the fix/diff-window-layout-restoration branch from 7bcc421 to ba93a3a Compare August 5, 2025 10:36
@ThomasK33
Copy link
Member

Gotcha, thanks for the video. I don't have those issues in my setup, though.

Could you push a minimal fixture that reproduces that bug? This would serve as a reproduction for me locally and validate that this fixes the issue itself.

@alvarosevilla95
Copy link
Contributor Author

Gotcha, thanks for the video. I don't have those issues in my setup, though.

Could you push a minimal fixture that reproduces that bug? This would serve as a reproduction for me locally and validate that this fixes the issue itself.

ah interesting, need to see what is it on my setup that is triggering it then.. i'll look into it and update / add a fixture accordingly 👍

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.

2 participants