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

@ -1,9 +1,12 @@
use std::{cmp, f32};
use std::{any::TypeId, cmp, f32};
use collections::HashSet;
use gpui::{px, Bounds, Pixels, ViewContext};
use language::Point;
use crate::{display_map::ToDisplayPoint, Editor, EditorMode, LineWithInvisibles};
use crate::{
display_map::ToDisplayPoint, DiffRowHighlight, Editor, EditorMode, LineWithInvisibles,
};
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum Autoscroll {
@ -103,7 +106,13 @@ impl Editor {
let mut target_top;
let mut target_bottom;
if let Some(first_highlighted_row) = &self.highlighted_display_rows(cx).first_entry() {
if let Some(first_highlighted_row) = &self
.highlighted_display_rows(
HashSet::from_iter(Some(TypeId::of::<DiffRowHighlight>())),
cx,
)
.first_entry()
{
target_top = *first_highlighted_row.key() as f32;
target_bottom = target_top + 1.;
} else {