Allow to toggle git hunk diffs (#11080)

Part of https://github.com/zed-industries/zed/issues/4523

Added two new actions with the default keybindings

```
"cmd-'": "editor::ToggleHunkDiff",
"cmd-\"": "editor::ExpandAllHunkDiffs",
```

that allow to browse git hunk diffs in Zed:


https://github.com/zed-industries/zed/assets/2690773/9a8a7d10-ed06-4960-b4ee-fe28fc5c4768


The hunks are dynamic and alter on user folds and modifications, or
toggle hidden, if the modifications were not adjacent to the expanded
hunk.


Release Notes:

- Added `editor::ToggleHunkDiff` (`cmd-'`) and
`editor::ExpandAllHunkDiffs` (`cmd-"`) actions to browse git hunk diffs
in Zed
This commit is contained in:
Kirill Bulatov 2024-05-01 22:47:36 +03:00 committed by GitHub
parent 5831d80f51
commit caa0d35b8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 3115 additions and 249 deletions

View file

@ -87,6 +87,9 @@ pub enum Event {
},
Reloaded,
DiffBaseChanged,
DiffUpdated {
buffer: Model<Buffer>,
},
LanguageChanged,
CapabilityChanged,
Reparsed,
@ -156,6 +159,7 @@ pub struct MultiBufferSnapshot {
edit_count: usize,
is_dirty: bool,
has_conflict: bool,
show_headers: bool,
}
/// A boundary between [`Excerpt`]s in a [`MultiBuffer`]
@ -269,6 +273,28 @@ struct ExcerptBytes<'a> {
impl MultiBuffer {
pub fn new(replica_id: ReplicaId, capability: Capability) -> Self {
Self {
snapshot: RefCell::new(MultiBufferSnapshot {
show_headers: true,
..MultiBufferSnapshot::default()
}),
buffers: RefCell::default(),
subscriptions: Topic::default(),
singleton: false,
capability,
replica_id,
title: None,
history: History {
next_transaction_id: clock::Lamport::default(),
undo_stack: Vec::new(),
redo_stack: Vec::new(),
transaction_depth: 0,
group_interval: Duration::from_millis(300),
},
}
}
pub fn without_headers(replica_id: ReplicaId, capability: Capability) -> Self {
Self {
snapshot: Default::default(),
buffers: Default::default(),
@ -1466,6 +1492,7 @@ impl MultiBuffer {
language::Event::FileHandleChanged => Event::FileHandleChanged,
language::Event::Reloaded => Event::Reloaded,
language::Event::DiffBaseChanged => Event::DiffBaseChanged,
language::Event::DiffUpdated => Event::DiffUpdated { buffer },
language::Event::LanguageChanged => Event::LanguageChanged,
language::Event::Reparsed => Event::Reparsed,
language::Event::DiagnosticsUpdated => Event::DiagnosticsUpdated,
@ -3588,6 +3615,10 @@ impl MultiBufferSnapshot {
})
})
}
pub fn show_headers(&self) -> bool {
self.show_headers
}
}
#[cfg(any(test, feature = "test-support"))]