Skip to content

git_ui: Allow opening a file with the diff hunks expanded#40616

Merged
cole-miller merged 1 commit intozed-industries:mainfrom
FloppyDisco:opening-a-file-from-GitPanel-will-open-the-editor-with-diff-hunks-expanded
Nov 14, 2025
Merged

git_ui: Allow opening a file with the diff hunks expanded#40616
cole-miller merged 1 commit intozed-industries:mainfrom
FloppyDisco:opening-a-file-from-GitPanel-will-open-the-editor-with-diff-hunks-expanded

Conversation

@FloppyDisco
Copy link
Contributor

So i just discovered editor::ExpandAllDiffHunks

I have been really missing the ability to look at changes NOT in a multi buffer so i was very pleased to finally figure out that this is already possible in Zed.

i have seen alot of discussion/issues requesting this feature so i think it is safe to say i'm not the only one that is not aware it exists.

i think the wording in the docs could better communicate what this feature actually is, however, i think an even better way to show users that this feature exists would be to just put it in front of them.

In the GitPanel:

  • menu::Confirm opens the project diff
  • menu::SecondaryConfirm opens the selected file in a new editor.

I think it would be REALLY nice if opening a file with SecondaryConfirm opened the file with the diff hunks already expanded and scrolled the editor to the first hunk.

ideally i see this being toggle-able in settings something like GitPanel - Open File with Diffs Expanded or something. so the user could turn this off if they preferred.

I tried creating a new keybinding using the new actions::Sequence
it was something like:

{
  "context": "GitPanel && ChangesList",
  "bindings": {
    "cmd-enter" : [ "actions::Sequence", ["menu:SecondaryConfirm", "editor::ToggleFocus", "editor::ExpandAllDiffHunks", "editor::GoToHunk"]]
  }
}

but the action sequence does not work. i think because opening the file is an async task.

i have a first attempt here, of just trying to get the diff hunks to expand after opening the file.
i tried to copy and paste the logic/structure as best i could from the confirm method in file_finder.rs:1432

it compiles, but it does not work, and i do not have enough experience in rust or in this project to figure out anything further.

if anyone was interested in working on this with me i would enjoy learning more and i think this would be a nice way to showcase this tool!

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Oct 19, 2025
@maxdeviant maxdeviant changed the title opening a file from GitPanel with the diff hunks expanded git_ui: Allow opening a file with the diff hunks expanded Oct 19, 2025
@cole-miller
Copy link
Member

Thanks! I like the idea of having the Open File option work this way. Implementation-wise, to make it work you'll need to do two things:

  • await on the active_editor.wait_for_diff_to_load() task before calling active_editor.expand_all_diff_hunks()
  • To navigate to the first diff hunk in the file, call active_editor.go_to_hunk_before_or_after_position() with appropriate arguments.

@FloppyDisco
Copy link
Contributor Author

FloppyDisco commented Nov 12, 2025

@cole-miller
Thank you for the direction! I'll work on this as soon as I can!

Do you think this should be optional? With a user setting?
and if so, do you have any recommendations for what the setting should be called.

@cole-miller
Copy link
Member

I don't think it needs to be a setting.

@FloppyDisco FloppyDisco force-pushed the opening-a-file-from-GitPanel-will-open-the-editor-with-diff-hunks-expanded branch from c31c69b to 8ceaaf0 Compare November 13, 2025 04:34
@zed-industries-bot
Copy link
Contributor

zed-industries-bot commented Nov 13, 2025

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against 753b998

@FloppyDisco FloppyDisco force-pushed the opening-a-file-from-GitPanel-will-open-the-editor-with-diff-hunks-expanded branch from 8ceaaf0 to d1865c3 Compare November 13, 2025 05:57
@FloppyDisco
Copy link
Contributor Author

hey @cole-miller
sorry i can't seem to figure out how to await wait_for_diff_to_load() correctly.

i'm not seeing it used anywhere else in the code ?
i saw some examples of calling an editor action inside a closure and awaiting that but when i do that here i just get compile errors saying the result is not a future.
^^^^^ `Result<Option<Shared<Task<()>>>, Error>` is not a future

@cole-miller
Copy link
Member

@FloppyDisco you'll need something like

if let Some(task) = editor.update(cx, |editor, cx| editor.wait_for_diff_to_load()).ok().flatten() {
    task.await;
}

@FloppyDisco FloppyDisco force-pushed the opening-a-file-from-GitPanel-will-open-the-editor-with-diff-hunks-expanded branch from d1865c3 to 753b998 Compare November 14, 2025 04:22
@FloppyDisco
Copy link
Contributor Author

uuuuuugh. i should have figured that one out. lol. thanks.

it seems to be working!

  • opens the file
  • expands the diff hunks
  • scrolls to the first hunk
Screen.Recording.2025-11-13.at.22.17.44.mov

@cole-miller
Copy link
Member

Thanks!

@cole-miller cole-miller merged commit 092071a into zed-industries:main Nov 14, 2025
23 checks passed
@JosephTLyons JosephTLyons moved this to 🚢 Shipped by Community in Git board Nov 19, 2025
11happy pushed a commit to 11happy/zed that referenced this pull request Dec 1, 2025
…ries#40616)

So i just discovered `editor::ExpandAllDiffHunks`

I have been really missing the ability to look at changes NOT in a multi
buffer so i was very pleased to finally figure out that this is already
possible in Zed.

i have seen alot of discussion/issues requesting this feature so i think
it is safe to say i'm not the only one that is not aware it exists.

i think the wording in the docs could better communicate what this
feature actually is, however, i think an even better way to show users
that this feature exists would be to just put it in front of them.

In the `GitPanel`:
- `menu::Confirm` opens the project diff
- `menu::SecondaryConfirm` opens the selected file in a new editor.

I think it would be REALLY nice if opening a file with
`SecondaryConfirm` opened the file with the diff hunks already expanded
and scrolled the editor to the first hunk.

ideally i see this being toggle-able in settings something like
`GitPanel - Open File with Diffs Expanded` or something. so the user
could turn this off if they preferred.

I tried creating a new keybinding using the new `actions::Sequence`
it was something like:
```json
{
  "context": "GitPanel && ChangesList",
  "bindings": {
    "cmd-enter" : [ "actions::Sequence", ["menu:SecondaryConfirm", "editor::ToggleFocus", "editor::ExpandAllDiffHunks", "editor::GoToHunk"]]
  }
}
```
but the action sequence does not work. i think because opening the file
is an async task.

i have a first attempt here, of just trying to get the diff hunks to
expand after opening the file.
i tried to copy and paste the logic/structure as best i could from the
confirm method in file_finder.rs:1432

it compiles, but it does not work, and i do not have enough experience
in rust or in this project to figure out anything further.

if anyone was interested in working on this with me i would enjoy
learning more and i think this would be a nice way to showcase this
tool!
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

Status: 🚢 Shipped by Community

Development

Successfully merging this pull request may close these issues.

3 participants