Fix two issues with diff highlights (#24309)

* fix syntax highlighting of deleted text when buffer language changes
* do not highlight entire untracked files as created, except in the
project diff view

Release Notes:

- N/A

Co-authored-by: ConradIrwin <conrad.irwin@gmail.com>
Co-authored-by: cole-miller <m@cole-miller.net>
This commit is contained in:
Max Brunsfeld 2025-02-05 13:29:39 -08:00 committed by GitHub
parent 9114ca973c
commit ca01a8b9cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 126 additions and 52 deletions

View file

@ -9,7 +9,7 @@ use gpui::{
actions, AnyElement, AnyView, App, AppContext, AsyncWindowContext, Entity, EventEmitter,
FocusHandle, Focusable, Render, Subscription, Task, WeakEntity,
};
use language::{Anchor, Buffer, Capability, OffsetRangeExt};
use language::{Anchor, Buffer, Capability, OffsetRangeExt, Point};
use multi_buffer::{MultiBuffer, PathKey};
use project::{buffer_store::BufferChangeSet, git::GitState, Project, ProjectPath};
use theme::ActiveTheme;
@ -293,11 +293,15 @@ impl ProjectDiff {
let change_set = diff_buffer.change_set;
let snapshot = buffer.read(cx).snapshot();
let diff_hunk_ranges = change_set
.read(cx)
.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot)
.map(|diff_hunk| diff_hunk.buffer_range.to_point(&snapshot))
.collect::<Vec<_>>();
let change_set = change_set.read(cx);
let diff_hunk_ranges = if change_set.base_text.is_none() {
vec![Point::zero()..snapshot.max_point()]
} else {
change_set
.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot)
.map(|diff_hunk| diff_hunk.buffer_range.to_point(&snapshot))
.collect::<Vec<_>>()
};
self.multibuffer.update(cx, |multibuffer, cx| {
multibuffer.set_excerpts_for_path(