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:
parent
5831d80f51
commit
caa0d35b8b
24 changed files with 3115 additions and 249 deletions
|
@ -109,6 +109,7 @@ pub struct Buffer {
|
|||
deferred_ops: OperationQueue<Operation>,
|
||||
capability: Capability,
|
||||
has_conflict: bool,
|
||||
diff_base_version: usize,
|
||||
}
|
||||
|
||||
/// An immutable, cheaply cloneable representation of a fixed
|
||||
|
@ -304,6 +305,8 @@ pub enum Event {
|
|||
Reloaded,
|
||||
/// The buffer's diff_base changed.
|
||||
DiffBaseChanged,
|
||||
/// Buffer's excerpts for a certain diff base were recalculated.
|
||||
DiffUpdated,
|
||||
/// The buffer's language was changed.
|
||||
LanguageChanged,
|
||||
/// The buffer's syntax trees were updated.
|
||||
|
@ -643,6 +646,7 @@ impl Buffer {
|
|||
was_dirty_before_starting_transaction: None,
|
||||
text: buffer,
|
||||
diff_base,
|
||||
diff_base_version: 0,
|
||||
git_diff: git::diff::BufferDiff::new(),
|
||||
file,
|
||||
capability,
|
||||
|
@ -872,6 +876,7 @@ impl Buffer {
|
|||
/// against the buffer text.
|
||||
pub fn set_diff_base(&mut self, diff_base: Option<String>, cx: &mut ModelContext<Self>) {
|
||||
self.diff_base = diff_base;
|
||||
self.diff_base_version += 1;
|
||||
if let Some(recalc_task) = self.git_diff_recalc(cx) {
|
||||
cx.spawn(|buffer, mut cx| async move {
|
||||
recalc_task.await;
|
||||
|
@ -885,6 +890,11 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns a number, unique per diff base set to the buffer.
|
||||
pub fn diff_base_version(&self) -> usize {
|
||||
self.diff_base_version
|
||||
}
|
||||
|
||||
/// Recomputes the Git diff status.
|
||||
pub fn git_diff_recalc(&mut self, cx: &mut ModelContext<Self>) -> Option<Task<()>> {
|
||||
let diff_base = self.diff_base.clone()?; // TODO: Make this an Arc
|
||||
|
@ -898,9 +908,10 @@ impl Buffer {
|
|||
|
||||
Some(cx.spawn(|this, mut cx| async move {
|
||||
let buffer_diff = diff.await;
|
||||
this.update(&mut cx, |this, _| {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.git_diff = buffer_diff;
|
||||
this.git_diff_update_count += 1;
|
||||
cx.emit(Event::DiffUpdated);
|
||||
})
|
||||
.ok();
|
||||
}))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue