Fix a couple of diff hunk issues (#24913)
- Fix hunks losing their expandedness when staged or unstaged - Disable collapsing hunks in the project diff editor Release Notes: - N/A --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
parent
56f13ddc50
commit
394bb8f4e6
3 changed files with 32 additions and 28 deletions
|
@ -281,13 +281,28 @@ enum DiffTransform {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct DiffTransformHunkInfo {
|
||||
excerpt_id: ExcerptId,
|
||||
hunk_start_anchor: text::Anchor,
|
||||
hunk_secondary_status: DiffHunkSecondaryStatus,
|
||||
}
|
||||
|
||||
impl Eq for DiffTransformHunkInfo {}
|
||||
|
||||
impl PartialEq for DiffTransformHunkInfo {
|
||||
fn eq(&self, other: &DiffTransformHunkInfo) -> bool {
|
||||
self.excerpt_id == other.excerpt_id && self.hunk_start_anchor == other.hunk_start_anchor
|
||||
}
|
||||
}
|
||||
|
||||
impl std::hash::Hash for DiffTransformHunkInfo {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.excerpt_id.hash(state);
|
||||
self.hunk_start_anchor.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ExcerptInfo {
|
||||
pub id: ExcerptId,
|
||||
|
@ -2361,7 +2376,7 @@ impl MultiBuffer {
|
|||
self.expand_or_collapse_diff_hunks(vec![Anchor::min()..Anchor::max()], true, cx);
|
||||
}
|
||||
|
||||
pub fn all_diff_hunks_expanded(&mut self) -> bool {
|
||||
pub fn all_diff_hunks_expanded(&self) -> bool {
|
||||
self.all_diff_hunks_expanded
|
||||
}
|
||||
|
||||
|
@ -2401,6 +2416,9 @@ impl MultiBuffer {
|
|||
expand: bool,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if self.all_diff_hunks_expanded && !expand {
|
||||
return;
|
||||
}
|
||||
self.sync(cx);
|
||||
let mut snapshot = self.snapshot.borrow_mut();
|
||||
let mut excerpt_edits = Vec::new();
|
||||
|
@ -2986,7 +3004,7 @@ impl MultiBuffer {
|
|||
let was_previously_expanded = old_expanded_hunks.contains(&hunk_info);
|
||||
let should_expand_hunk = match &change_kind {
|
||||
DiffChangeKind::DiffUpdated { base_changed: true } => {
|
||||
self.all_diff_hunks_expanded
|
||||
self.all_diff_hunks_expanded || was_previously_expanded
|
||||
}
|
||||
DiffChangeKind::ExpandOrCollapseHunks { expand } => {
|
||||
let intersects = hunk_buffer_range.is_empty()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue