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
|
@ -13193,28 +13193,6 @@ async fn test_diff_base_change_with_expanded_diff_hunks(
|
||||||
|
|
||||||
cx.set_diff_base("new diff base!");
|
cx.set_diff_base("new diff base!");
|
||||||
executor.run_until_parked();
|
executor.run_until_parked();
|
||||||
cx.assert_state_with_diff(
|
|
||||||
r#"
|
|
||||||
use some::mod2;
|
|
||||||
|
|
||||||
const A: u32 = 42;
|
|
||||||
const C: u32 = 42;
|
|
||||||
|
|
||||||
fn main(ˇ) {
|
|
||||||
//println!("hello");
|
|
||||||
|
|
||||||
println!("world");
|
|
||||||
//
|
|
||||||
//
|
|
||||||
}
|
|
||||||
"#
|
|
||||||
.unindent(),
|
|
||||||
);
|
|
||||||
|
|
||||||
cx.update_editor(|editor, window, cx| {
|
|
||||||
editor.expand_all_diff_hunks(&ExpandAllHunkDiffs, window, cx);
|
|
||||||
});
|
|
||||||
executor.run_until_parked();
|
|
||||||
cx.assert_state_with_diff(
|
cx.assert_state_with_diff(
|
||||||
r#"
|
r#"
|
||||||
- new diff base!
|
- new diff base!
|
||||||
|
|
|
@ -4829,7 +4829,15 @@ impl EditorElement {
|
||||||
) {
|
) {
|
||||||
for (_, hunk_hitbox) in &layout.display_hunks {
|
for (_, hunk_hitbox) in &layout.display_hunks {
|
||||||
if let Some(hunk_hitbox) = hunk_hitbox {
|
if let Some(hunk_hitbox) = hunk_hitbox {
|
||||||
window.set_cursor_style(CursorStyle::PointingHand, hunk_hitbox);
|
if !self
|
||||||
|
.editor
|
||||||
|
.read(cx)
|
||||||
|
.buffer()
|
||||||
|
.read(cx)
|
||||||
|
.all_diff_hunks_expanded()
|
||||||
|
{
|
||||||
|
window.set_cursor_style(CursorStyle::PointingHand, hunk_hitbox);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5717,7 +5725,7 @@ impl EditorElement {
|
||||||
window.on_mouse_event({
|
window.on_mouse_event({
|
||||||
let position_map = layout.position_map.clone();
|
let position_map = layout.position_map.clone();
|
||||||
let editor = self.editor.clone();
|
let editor = self.editor.clone();
|
||||||
let multi_buffer_range =
|
let diff_hunk_range =
|
||||||
layout
|
layout
|
||||||
.display_hunks
|
.display_hunks
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -5753,7 +5761,7 @@ impl EditorElement {
|
||||||
Self::mouse_left_down(
|
Self::mouse_left_down(
|
||||||
editor,
|
editor,
|
||||||
event,
|
event,
|
||||||
multi_buffer_range.clone(),
|
diff_hunk_range.clone(),
|
||||||
&position_map,
|
&position_map,
|
||||||
line_numbers.as_ref(),
|
line_numbers.as_ref(),
|
||||||
window,
|
window,
|
||||||
|
|
|
@ -281,13 +281,28 @@ enum DiffTransform {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
struct DiffTransformHunkInfo {
|
struct DiffTransformHunkInfo {
|
||||||
excerpt_id: ExcerptId,
|
excerpt_id: ExcerptId,
|
||||||
hunk_start_anchor: text::Anchor,
|
hunk_start_anchor: text::Anchor,
|
||||||
hunk_secondary_status: DiffHunkSecondaryStatus,
|
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)]
|
#[derive(Clone)]
|
||||||
pub struct ExcerptInfo {
|
pub struct ExcerptInfo {
|
||||||
pub id: ExcerptId,
|
pub id: ExcerptId,
|
||||||
|
@ -2361,7 +2376,7 @@ impl MultiBuffer {
|
||||||
self.expand_or_collapse_diff_hunks(vec![Anchor::min()..Anchor::max()], true, cx);
|
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
|
self.all_diff_hunks_expanded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2401,6 +2416,9 @@ impl MultiBuffer {
|
||||||
expand: bool,
|
expand: bool,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) {
|
) {
|
||||||
|
if self.all_diff_hunks_expanded && !expand {
|
||||||
|
return;
|
||||||
|
}
|
||||||
self.sync(cx);
|
self.sync(cx);
|
||||||
let mut snapshot = self.snapshot.borrow_mut();
|
let mut snapshot = self.snapshot.borrow_mut();
|
||||||
let mut excerpt_edits = Vec::new();
|
let mut excerpt_edits = Vec::new();
|
||||||
|
@ -2986,7 +3004,7 @@ impl MultiBuffer {
|
||||||
let was_previously_expanded = old_expanded_hunks.contains(&hunk_info);
|
let was_previously_expanded = old_expanded_hunks.contains(&hunk_info);
|
||||||
let should_expand_hunk = match &change_kind {
|
let should_expand_hunk = match &change_kind {
|
||||||
DiffChangeKind::DiffUpdated { base_changed: true } => {
|
DiffChangeKind::DiffUpdated { base_changed: true } => {
|
||||||
self.all_diff_hunks_expanded
|
self.all_diff_hunks_expanded || was_previously_expanded
|
||||||
}
|
}
|
||||||
DiffChangeKind::ExpandOrCollapseHunks { expand } => {
|
DiffChangeKind::ExpandOrCollapseHunks { expand } => {
|
||||||
let intersects = hunk_buffer_range.is_empty()
|
let intersects = hunk_buffer_range.is_empty()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue