Skip to content

git: Introduce restore and next action#50324

Merged
dinocosta merged 6 commits intomainfrom
git-restore-and-next
Mar 9, 2026
Merged

git: Introduce restore and next action#50324
dinocosta merged 6 commits intomainfrom
git-restore-and-next

Conversation

@dinocosta
Copy link
Copy Markdown
Member

@dinocosta dinocosta commented Feb 27, 2026

Before you mark this PR as ready for review, make sure that you have:

  • Added a solid test coverage and/or screenshots from doing manual testing
  • Done a self-review taking into account security and performance aspects
  • Aligned any UI changes with the UI checklist

Release Notes:

  • Added a git: restore and next action that restores the diff hunk at the cursor and conditionally moves to the next one. In the git diff view, the default restore keybinding (cmd-alt-z on macOS, ctrl-k ctrl-r on Linux/Windows) now triggers this action instead of git: restore.

dinocosta and others added 2 commits February 27, 2026 16:47
Similar to `git::StageAndNext` and `git::UnstageAndNext`, these changes
introduce a `git::RestoreAndNext` action.

There's a `TODO!` regarding multiple calls to `Editor.change_selections`
which we can likely consolidate, and tests will be added in a next
commit.

Co-authored-by: Afonso <4775087+afonsograca@users.noreply.github.com>
Co-authored-by: Afonso <4775087+afonsograca@users.noreply.github.com>
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 27, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Feb 27, 2026
* Update `Editor.restore_and_next` to leverage `Editor.go_to_next_hunk`
* Remove irrelevant `TODO!`
* Update tests to confirm behavior change in `Editor.restore_and_next`
@dinocosta dinocosta self-assigned this Feb 28, 2026
Update the default keymaps for all platforms (macOS, Windows & Linux) in
order to map the default binding for `git::Restore` to map to
`git::RestoreAndNext` when the user is focused on the `GitDiff` view
only.

This way we don't change the default behavior when the user is editing a
single file or a multibuffer but, in the context of the git diff, are
able to have the diff hunk be restored and move to the next one.
@dinocosta dinocosta marked this pull request as ready for review March 4, 2026 18:23
- Update the `editor::Editor::hunk_before_position` and
  `editor::Editor::hunk_after_position` methods to accept a
  `wrap_around` parameter, contorlling whether the caller whishes for
  the search for the previous or next hunk to wrap around in the buffer
- Refactor all callers to default this parameter to true
- Refactor `editor::Editor::do_stage_or_unstage_and_next` to leverage
  this new parameter in
  `editor::Editor::go_to_hunk_before_or_after_position`, keeping the
  logic of only wrapping around if
  `multi_buffer::MultiBuffer::all_diff_hunks_expanded` returns false
- Refactor `editor::Editor::restore_and_next` method to use the wrap
  around logic as `editor::Editor::do_stage_or_unstage_and_next`
@dinocosta dinocosta enabled auto-merge (squash) March 9, 2026 10:40
@dinocosta dinocosta merged commit 0a436be into main Mar 9, 2026
29 checks passed
@dinocosta dinocosta deleted the git-restore-and-next branch March 9, 2026 10:50
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 staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant