Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lingering phantom diff in editor #18405

Closed
1 task done
maxdeviant opened this issue Sep 26, 2024 · 0 comments · Fixed by #18454
Closed
1 task done

Lingering phantom diff in editor #18405

maxdeviant opened this issue Sep 26, 2024 · 0 comments · Fixed by #18454
Labels
defect [core label] editor Feedback for code editing, formatting, editor iterations, etc git Git integration feedback

Comments

@maxdeviant
Copy link
Member

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

Reproduction steps at 1105876:

  1. Open this file
  2. On line 29, press Enter twice to produce a diff consisting of two empty lines
  3. Click in the gutter to expand the hunk
    Screenshot 2024-09-26 at 1 08 18 PM
  4. Click the "Discard Hunk" button
  5. Press Cmd + Z to undo the revert
  6. Observe that the diff is back, but only one of the lines is highlighted:
    Screenshot 2024-09-26 at 1 05 56 PM
  7. Click in the gutter to expand the hunk again
  8. Click the "Discard Hunk" button
  9. 💥 There is now a phantom diff line
Screenshot 2024-09-26 at 1 09 32 PM

Environment

Zed: v0.156.0 (Zed Nightly 6167688)
OS: macOS 14.4.0
Memory: 128 GiB
Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

No response

@maxdeviant maxdeviant added defect [core label] triage Maintainer needs to classify the issue admin read Pending admin review labels Sep 26, 2024
@notpeter notpeter added editor Feedback for code editing, formatting, editor iterations, etc git Git integration feedback and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Sep 26, 2024
maxbrunsfeld added a commit that referenced this issue 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect [core label] editor Feedback for code editing, formatting, editor iterations, etc git Git integration feedback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants