Improve calculation of which lines are new when auto-indenting
This commit is contained in:
parent
6b9c1e78c1
commit
09ed149184
2 changed files with 121 additions and 44 deletions
|
@ -756,8 +756,18 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut Muta
|
|||
});
|
||||
|
||||
cx.add_model(|cx| {
|
||||
let text = "fn a() {\n {\n b()?\n }\n\n Ok(())\n}";
|
||||
let text = "
|
||||
fn a() {
|
||||
{
|
||||
b()?
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
"
|
||||
.unindent();
|
||||
let mut buffer = Buffer::new(0, text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
|
||||
// Delete a closing curly brace changes the suggested indent for the line.
|
||||
buffer.edit_with_autoindent(
|
||||
[(Point::new(3, 4)..Point::new(3, 5), "")],
|
||||
IndentSize::spaces(4),
|
||||
|
@ -765,9 +775,19 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut Muta
|
|||
);
|
||||
assert_eq!(
|
||||
buffer.text(),
|
||||
"fn a() {\n {\n b()?\n \n\n Ok(())\n}"
|
||||
"
|
||||
fn a() {
|
||||
{
|
||||
b()?
|
||||
|
|
||||
Ok(())
|
||||
}
|
||||
"
|
||||
.replace("|", "") // included in the string to preserve trailing whites
|
||||
.unindent()
|
||||
);
|
||||
|
||||
// Manually editing the leading whitespace
|
||||
buffer.edit_with_autoindent(
|
||||
[(Point::new(3, 0)..Point::new(3, 12), "")],
|
||||
IndentSize::spaces(4),
|
||||
|
@ -775,7 +795,15 @@ fn test_autoindent_does_not_adjust_lines_with_unchanged_suggestion(cx: &mut Muta
|
|||
);
|
||||
assert_eq!(
|
||||
buffer.text(),
|
||||
"fn a() {\n {\n b()?\n\n\n Ok(())\n}"
|
||||
"
|
||||
fn a() {
|
||||
{
|
||||
b()?
|
||||
|
||||
Ok(())
|
||||
}
|
||||
"
|
||||
.unindent()
|
||||
);
|
||||
buffer
|
||||
});
|
||||
|
@ -832,6 +860,45 @@ fn test_autoindent_with_edit_at_end_of_buffer(cx: &mut MutableAppContext) {
|
|||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_multi_line_insertion(cx: &mut MutableAppContext) {
|
||||
cx.add_model(|cx| {
|
||||
let text = "
|
||||
const a: usize = 1;
|
||||
fn b() {
|
||||
if c {
|
||||
let d = 2;
|
||||
}
|
||||
}
|
||||
"
|
||||
.unindent();
|
||||
|
||||
let mut buffer = Buffer::new(0, text, cx).with_language(Arc::new(rust_lang()), cx);
|
||||
buffer.edit_with_autoindent(
|
||||
[(Point::new(3, 0)..Point::new(3, 0), "e(\n f()\n);\n")],
|
||||
IndentSize::spaces(4),
|
||||
cx,
|
||||
);
|
||||
assert_eq!(
|
||||
buffer.text(),
|
||||
"
|
||||
const a: usize = 1;
|
||||
fn b() {
|
||||
if c {
|
||||
e(
|
||||
f()
|
||||
);
|
||||
let d = 2;
|
||||
}
|
||||
}
|
||||
"
|
||||
.unindent()
|
||||
);
|
||||
|
||||
buffer
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn test_autoindent_disabled(cx: &mut MutableAppContext) {
|
||||
cx.add_model(|cx| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue