Skip to content

Expand git diffs when clicking the gutter strip, display their controls in a block above#18313

Merged
maxbrunsfeld merged 11 commits intomainfrom
new-git-hunk-buttons
Sep 25, 2024
Merged

Expand git diffs when clicking the gutter strip, display their controls in a block above#18313
maxbrunsfeld merged 11 commits intomainfrom
new-git-hunk-buttons

Conversation

@maxbrunsfeld
Copy link
Copy Markdown
Collaborator

@maxbrunsfeld maxbrunsfeld commented Sep 25, 2024

Todo:

  • Tooltips for hunk buttons
  • Buttons to go to next and previous hunk
  • Ellipsis button that opens a context menu with Revert all

/cc @iamnbutler @danilo-leal for design 👀

Release Notes:

  • Changed the behavior of the git gutter so that diff hunk are expanded immediately when clicking the gutter, and hunk controls are displayed above the hunk.

maxbrunsfeld and others added 2 commits September 24, 2024 17:55
Co-authored-by: Marshall <marshall@zed.dev>
* Add a gutter strip that matches the hunk
* Use the modified color for both parts of modified hunks' gutter strip
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Sep 25, 2024
@maxbrunsfeld maxbrunsfeld merged commit 21a0239 into main Sep 25, 2024
@maxbrunsfeld maxbrunsfeld deleted the new-git-hunk-buttons branch September 25, 2024 19:50
@maxdeviant maxdeviant mentioned this pull request Sep 25, 2024
2 tasks
maxbrunsfeld added a commit that referenced this pull request Sep 27, 2024
Fixes #18405

In #18313, we introduced a
problem where git addition highlights might spuriously return when
undoing certain changes. It turned out, there were already some cases
where git hunk highlighting was incorrect when editing at the boundaries
of expanded diff hunks.

In this PR, I've introduced a test helper method for more rigorously
(and readably) testing the editor's git state. You can assert about the
entire state of an editor's diff decorations using a formatted diff:

```rust
    cx.assert_diff_hunks(
        r#"
        - use some::mod1;
          use some::mod2;
          const A: u32 = 42;
        - const B: u32 = 42;
          const C: u32 = 42;
          fn main() {
        -     println!("hello");
        +     //println!("hello");
              println!("world");
        +     //
        +     //
          }
          fn another() {
              println!("another");
        +     println!("another");
          }
        - fn another2() {
              println!("another2");
          }
        "#
        .unindent(),
    );
```

This will assert about the editor's actual row highlights, not just the
editor's internal hunk-tracking state.

I rewrote all of our editor diff tests to use these more high-level
assertions, and it caught the new bug, as well as some pre-existing bugs
in the highlighting of added content.

The problem was how we *remove* highlighted rows. Previously, it relied
on supplying exactly the same range as one that we had previously
highlighted. I've added a `remove_highlighted_rows(ranges)` APIs which
is much simpler - it clears out any row ranges that intersect the given
ranges (which is all that we need for the Git diff use case).

Release Notes:

- N/A
noaccOS pushed a commit to noaccOS/zed that referenced this pull request Oct 19, 2024
…ls in a block above (zed-industries#18313)

Todo:

* [x] Tooltips for hunk buttons
* [x] Buttons to go to next and previous hunk
* [x] Ellipsis button that opens a context menu with `Revert all`

/cc @iamnbutler @danilo-leal for design 👀 

Release Notes:

- Changed the behavior of the git gutter so that diff hunk are expanded
immediately when clicking the gutter, and hunk controls are displayed
above the hunk.

---------

Co-authored-by: Marshall <marshall@zed.dev>
Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
noaccOS pushed a commit to noaccOS/zed that referenced this pull request Oct 19, 2024
Fixes zed-industries#18405

In zed-industries#18313, we introduced a
problem where git addition highlights might spuriously return when
undoing certain changes. It turned out, there were already some cases
where git hunk highlighting was incorrect when editing at the boundaries
of expanded diff hunks.

In this PR, I've introduced a test helper method for more rigorously
(and readably) testing the editor's git state. You can assert about the
entire state of an editor's diff decorations using a formatted diff:

```rust
    cx.assert_diff_hunks(
        r#"
        - use some::mod1;
          use some::mod2;
          const A: u32 = 42;
        - const B: u32 = 42;
          const C: u32 = 42;
          fn main() {
        -     println!("hello");
        +     //println!("hello");
              println!("world");
        +     //
        +     //
          }
          fn another() {
              println!("another");
        +     println!("another");
          }
        - fn another2() {
              println!("another2");
          }
        "#
        .unindent(),
    );
```

This will assert about the editor's actual row highlights, not just the
editor's internal hunk-tracking state.

I rewrote all of our editor diff tests to use these more high-level
assertions, and it caught the new bug, as well as some pre-existing bugs
in the highlighting of added content.

The problem was how we *remove* highlighted rows. Previously, it relied
on supplying exactly the same range as one that we had previously
highlighted. I've added a `remove_highlighted_rows(ranges)` APIs which
is much simpler - it clears out any row ranges that intersect the given
ranges (which is all that we need for the Git diff use case).

Release Notes:

- N/A
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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants