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

Fix pairs of almost-adjacent hunks toggling together #24355

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ impl EditorElement {
let mut modifiers = event.modifiers;

if let Some(hovered_hunk) = hovered_hunk {
editor.toggle_diff_hunks_in_ranges(vec![hovered_hunk], cx);
editor.toggle_diff_hunks_in_ranges(vec![hovered_hunk.start..hovered_hunk.start], cx);
cx.notify();
return;
} else if gutter_hitbox.is_hovered(window) {
Expand Down
41 changes: 41 additions & 0 deletions crates/multi_buffer/src/multi_buffer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,47 @@ fn test_diff_hunks_in_range(cx: &mut TestAppContext) {
);
}

#[gpui::test]
fn test_toggle_adjacent_hunks(cx: &mut TestAppContext) {
let base_text = "b\n";
let text = "a\nb\nc\n";

let buffer = cx.new(|cx| Buffer::local(text, cx));
let change_set = cx.new(|cx| BufferChangeSet::new_with_base_text(&base_text, &buffer, cx));
let multibuffer = cx.new(|cx| MultiBuffer::singleton(buffer.clone(), cx));

let (mut snapshot, mut subscription) = multibuffer.update(cx, |multibuffer, cx| {
multibuffer.add_change_set(change_set.clone(), cx);
(multibuffer.snapshot(cx), multibuffer.subscribe())
});

assert_new_snapshot(
&multibuffer,
&mut snapshot,
&mut subscription,
cx,
"a\nb\nc\n",
);

multibuffer.update(cx, |multibuffer, cx| {
let start = multibuffer
.buffer_point_to_anchor(&buffer, Point::new(0, 0), cx)
.unwrap();
let end = multibuffer
.buffer_point_to_anchor(&buffer, Point::new(1, 0), cx)
.unwrap();
multibuffer.expand_diff_hunks(vec![start..end], cx);
});

assert_new_snapshot(
&multibuffer,
&mut snapshot,
&mut subscription,
cx,
"+ a\n b\n c\n",
);
}

#[gpui::test]
fn test_editing_text_in_diff_hunks(cx: &mut TestAppContext) {
let base_text = "one\ntwo\nfour\nfive\nsix\nseven\n";
Expand Down
Loading