Skip to content

Commit

Permalink
Remove marked diff state API
Browse files Browse the repository at this point in the history
  • Loading branch information
mikayla-maki committed May 18, 2024
1 parent 2a6f815 commit a346f4e
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 446 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test-support = [
"gpui/test-support",
"multi_buffer/test-support",
"project/test-support",
"theme/test-support",
"util/test-support",
"workspace/test-support",
"tree-sitter-rust",
Expand Down Expand Up @@ -86,6 +87,7 @@ release_channel.workspace = true
rand.workspace = true
settings = { workspace = true, features = ["test-support"] }
text = { workspace = true, features = ["test-support"] }
theme = { workspace = true, features = ["test-support"] }
tree-sitter-html.workspace = true
tree-sitter-rust.workspace = true
tree-sitter-typescript.workspace = true
Expand Down
215 changes: 107 additions & 108 deletions crates/editor/src/editor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4297,8 +4297,7 @@ async fn test_select_previous_multibuffer(cx: &mut gpui::TestAppContext) {
"aaa\n«bbb\nccc\n»ddd"
},
],
)
.await;
);

cx.assert_editor_state(indoc! {"
ˇbbb
Expand Down Expand Up @@ -10241,91 +10240,110 @@ async fn test_fold_unfold_diff(executor: BackgroundExecutor, cx: &mut gpui::Test
async fn test_toggle_diff_expand_in_multi_buffer(cx: &mut gpui::TestAppContext) {
init_test(cx, |_| {});

let mut editor_cx = EditorTestContext::new_multibuffer(
cx,
[
&(
"main.rs",
indoc! {"
«aaaa
cccc
dddd
»eeee
ffff
«gggg
hhhh
»iiii
jjjj
"},
indoc! {"
aaaa
bbbb
cccc
dddd
eeee
ffff
gggg
hhhh
iiii
jjjj
"},
),
&(
"other.rs",
indoc! {"
«llll
mmmm
1n1n1n1n1
»oooo
pppp
«qqqq
rrrr
»ssss
tttt
uuuu
"},
indoc! {"
llll
mmmm
nnnn
oooo
pppp
qqqq
rrrr
ssss
tttt
uuuu
"},
),
&(
"lib.rs",
indoc! {"
«vvvv
wwww
xxxx
»yyyy
zzzz
«@@@@
{{{{
»||||
}}}}
«~~~~
\u{7f}\u{7f}\u{7f}\u{7f}»
"},
indoc! {"
vvvv
wwww
xxxx
yyyy
zzzz
{{{{
||||
}}}}
~~~~
\u{7f}\u{7f}\u{7f}\u{7f}
"},
),
],
let cols = 4;
let rows = 10;
let sample_text_1 = sample_text(rows, cols, 'a');
assert_eq!(
sample_text_1,
"aaaa\nbbbb\ncccc\ndddd\neeee\nffff\ngggg\nhhhh\niiii\njjjj"
);
let modified_sample_text_1 = "aaaa\ncccc\ndddd\neeee\nffff\ngggg\nhhhh\niiii\njjjj";
let sample_text_2 = sample_text(rows, cols, 'l');
assert_eq!(
sample_text_2,
"llll\nmmmm\nnnnn\noooo\npppp\nqqqq\nrrrr\nssss\ntttt\nuuuu"
);
let modified_sample_text_2 = "llll\nmmmm\n1n1n1n1n1\noooo\npppp\nqqqq\nrrrr\nssss\ntttt\nuuuu";
let sample_text_3 = sample_text(rows, cols, 'v');
assert_eq!(
sample_text_3,
"vvvv\nwwww\nxxxx\nyyyy\nzzzz\n{{{{\n||||\n}}}}\n~~~~\n\u{7f}\u{7f}\u{7f}\u{7f}"
);
let modified_sample_text_3 =
"vvvv\nwwww\nxxxx\nyyyy\nzzzz\n@@@@\n{{{{\n||||\n}}}}\n~~~~\n\u{7f}\u{7f}\u{7f}\u{7f}";
let buffer_1 = cx.new_model(|cx| {
let mut buffer = Buffer::local(modified_sample_text_1.to_string(), cx);
buffer.set_diff_base(Some(sample_text_1.clone()), cx);
buffer
});
let buffer_2 = cx.new_model(|cx| {
let mut buffer = Buffer::local(modified_sample_text_2.to_string(), cx);
buffer.set_diff_base(Some(sample_text_2.clone()), cx);
buffer
});
let buffer_3 = cx.new_model(|cx| {
let mut buffer = Buffer::local(modified_sample_text_3.to_string(), cx);
buffer.set_diff_base(Some(sample_text_3.clone()), cx);
buffer
});

let multi_buffer = cx.new_model(|cx| {
let mut multibuffer = MultiBuffer::new(0, ReadWrite);
multibuffer.push_excerpts(
buffer_1.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
],
cx,
);
multibuffer.push_excerpts(
buffer_2.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
],
cx,
);
multibuffer.push_excerpts(
buffer_3.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
],
cx,
);
multibuffer
});

let fs = FakeFs::new(cx.executor());
fs.insert_tree(
"/a",
json!({
"main.rs": modified_sample_text_1,
"other.rs": modified_sample_text_2,
"lib.rs": modified_sample_text_3,
}),
)
.await;

Expand Down Expand Up @@ -10371,33 +10389,14 @@ async fn test_toggle_diff_expand_in_multi_buffer(cx: &mut gpui::TestAppContext)
),
];

editor_cx.assert_editor_diff_state(indoc! {"
aaaa
>>REMOVED>>bbbb>>REMOVED>>
cccc
dddd
qqqq
rrrr
llll
mmmm
>>MODIFIED>>1n1n1n1n1|>FROM|>nnnn>>MODIFIED>>
vvvv
wwww
xxxx
>>ADDED>>@@@@>>ADDED>>
{{{{
~~~~
\u{7f}\u{7f}\u{7f}\u{7f}
"});

editor_cx.update_editor(|editor, cx| {
multi_buffer_editor.update(cx, |editor, cx| {
let snapshot = editor.snapshot(cx);
let all_hunks = editor_hunks(editor, &snapshot, cx);
let all_expanded_hunks = expanded_hunks(&editor, &snapshot, cx);
assert_eq!(expanded_hunks_background_highlights(editor, cx), Vec::new());
assert_eq!(all_hunks, expected_all_hunks);
assert_eq!(all_expanded_hunks, Vec::new());
})
});

multi_buffer_editor.update(cx, |editor, cx| {
editor.select_all(&SelectAll, cx);
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/src/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ mod tests {
init_test(cx);
});

let mut cx = EditorTestContext::new_multibuffer(cx, [&"«abc\ndefg»\n«hijkl\nmn»"]).await;
let mut cx = EditorTestContext::new_multibuffer(cx, [&"«abc\ndefg»\n«hijkl\nmn»"]);
cx.update_editor(|editor, cx| {
editor.move_right(&Default::default(), cx);
editor.move_right(&Default::default(), cx)
Expand Down

0 comments on commit a346f4e

Please sign in to comment.