Skip to content

editor: Fix git-hunk toggling for adjacent hunks#43187

Merged
kubkon merged 3 commits intozed-industries:mainfrom
seanstrom:seanstrom/fix-adjacent-git-diff-hunk-toggle
Dec 18, 2025
Merged

editor: Fix git-hunk toggling for adjacent hunks#43187
kubkon merged 3 commits intozed-industries:mainfrom
seanstrom:seanstrom/fix-adjacent-git-diff-hunk-toggle

Conversation

@seanstrom
Copy link
Contributor

Closes #42934

Release Notes:

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Nov 20, 2025
@seanstrom
Copy link
Contributor Author

Commentary

  • The command for toggling selected git-diff hunks as some complex behaviours depending on the position of the cursor, and whether there are multiple git-hunks near each other (separated by a line, or without a line separation).
  • I've left some notes and recordings attached to issue vim_mode: Cannot open deletion diff hunk when it is right after the other diffs #42934
  • And this PR creates a failing test for one of the cases with adjacent hunks, however, we may want to add more tests and define the intended behaviour of the hunk-toggling command to avoid more regressions.

@seanstrom seanstrom changed the title editor: fix git-hunk toggling for adjacent hunks editor: Fix git-hunk toggling for adjacent hunks Nov 20, 2025
Comment on lines +2466 to +2467
// why do we need to subtract 1 from the start offset?
// let start = start.saturating_sub_usize(1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is questionable, since it seems to break some existing behaviour when attempting to collapse a diff-hunk when the cursor is a line below the expanded hunk.

Prior to this change, the cursor could be at the beginning of the line below an expanded hunk, and the toggle-selected-hunks command would collapse the hunk above the cursor.

After this change, when the cursor is a line below an expanded hunk, and the cursor is a line above a deletion hunk, the toggle-selected-hunks command will expand the deletion hunk.

@seanstrom
Copy link
Contributor Author

Here's a screen recording of the current behaviour with the changes in this PR:

zed-pr-toggle-hunk-behaviour-fix-v1.mp4

This change adds a failing test to the editor test suite for a scenario where toggling neighboring git-hunks does work as expected because the second hunk is not targeted when the first hunk is already expanded
# 50-character subject line
#
# 72-character wrapped longer description.
#
# * Maybe try answering these questions: *
# * What did I change? *
# * Why did I change it? *
# * How did I change it? *
@seanstrom seanstrom force-pushed the seanstrom/fix-adjacent-git-diff-hunk-toggle branch from 99c3d29 to 0960a0f Compare November 23, 2025 01:47
@cole-miller cole-miller removed their assignment Dec 16, 2025
@kubkon kubkon self-assigned this Dec 16, 2025
@kubkon
Copy link
Member

kubkon commented Dec 18, 2025

Thanks for the PR! I had a closer look and the proposed change does not seem the right solution as it regresses other behaviour plus makes it generally inconsistent. However, I did discuss that with the team and we have an idea how to approach this. With that in mind, I'm gonna go ahead and close the PR and hopefully get a fix up ASAP.

@kubkon kubkon closed this Dec 18, 2025
@github-project-automation github-project-automation bot moved this from Community PRs to Done in Quality Week – December 2025 Dec 18, 2025
@seanstrom
Copy link
Contributor Author

Thanks for taking a look!

Glad to hear there was discussion, hope this was helpful for kickstarting the real solution, eager to learn more about it when it’s ready.

feel free to tag me in the next pr, happy to follow along and help out if needed 👍

@kubkon kubkon reopened this Dec 18, 2025
@kubkon
Copy link
Member

kubkon commented Dec 18, 2025

I've done some more digging and I agree with you that subtracting 1 from multibuffer offset makes little sense and it doesn't seem to regress anything (anything that we have coverage for). It also keeps things consistent, whereas trying to special-case this would inevitably result in inconsistent handling depending if we are dealing with single empty cursor selection or more elaborate selections. I am therefore inclined to merge this PR with some minor cleanups and rebase on main (already done that locally, will push in a minute). If we regress something that we don't have coverage for, we'll revert and add a new test case and whatnot.

@kubkon kubkon merged commit 2d071b0 into zed-industries:main Dec 18, 2025
24 checks passed
@seanstrom seanstrom deleted the seanstrom/fix-adjacent-git-diff-hunk-toggle branch December 19, 2025 16:26
@seanstrom
Copy link
Contributor Author

awesome! thanks @kubkon 🙌

rtfeldman pushed a commit that referenced this pull request Jan 5, 2026
Closes #42934 

Release Notes:

- Fix toggling adjacent git-diff hunks based on the reported behaviour
in #42934

---------

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
LivioGama pushed a commit to LivioGama/zed that referenced this pull request Jan 20, 2026
Closes zed-industries#42934 

Release Notes:

- Fix toggling adjacent git-diff hunks based on the reported behaviour
in zed-industries#42934

---------

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
LivioGama pushed a commit to LivioGama/zed that referenced this pull request Jan 20, 2026
Closes zed-industries#42934 

Release Notes:

- Fix toggling adjacent git-diff hunks based on the reported behaviour
in zed-industries#42934

---------

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
LivioGama pushed a commit to LivioGama/zed that referenced this pull request Feb 15, 2026
Closes zed-industries#42934 

Release Notes:

- Fix toggling adjacent git-diff hunks based on the reported behaviour
in zed-industries#42934

---------

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

Development

Successfully merging this pull request may close these issues.

vim_mode: Cannot open deletion diff hunk when it is right after the other diffs

3 participants