editor: Fix multicursor indent edge case where few lines would indent incorrectly (#30461)
This should have been part of [editor: Fix inconsistent relative indent when using tab with multi cursors](https://github.com/zed-industries/zed/pull/29519) Before / After: https://github.com/user-attachments/assets/b7ab0eef-2764-44dc-b51f-b96dccd5ecb3 Release Notes: - N/A --------- Co-authored-by: Ben Kunkle <ben.kunkle@gmail.com>
This commit is contained in:
parent
471e02d48f
commit
172a475515
2 changed files with 123 additions and 10 deletions
|
@ -2871,7 +2871,8 @@ async fn test_tab_in_leading_whitespace_auto_indents_lines(cx: &mut TestAppConte
|
|||
);
|
||||
cx.update_buffer(|buffer, cx| buffer.set_language(Some(language), cx));
|
||||
|
||||
// when all cursors are to the left of the suggested indent, then auto-indent all.
|
||||
// test when all cursors are not at suggested indent
|
||||
// then simply move to their suggested indent location
|
||||
cx.set_state(indoc! {"
|
||||
const a: B = (
|
||||
c(
|
||||
|
@ -2888,9 +2889,8 @@ async fn test_tab_in_leading_whitespace_auto_indents_lines(cx: &mut TestAppConte
|
|||
);
|
||||
"});
|
||||
|
||||
// cursors that are already at the suggested indent level do not move
|
||||
// until other cursors that are to the left of the suggested indent
|
||||
// auto-indent.
|
||||
// test cursor already at suggested indent not moving when
|
||||
// other cursors are yet to reach their suggested indents
|
||||
cx.set_state(indoc! {"
|
||||
ˇ
|
||||
const a: B = (
|
||||
|
@ -2914,8 +2914,7 @@ async fn test_tab_in_leading_whitespace_auto_indents_lines(cx: &mut TestAppConte
|
|||
ˇ)
|
||||
);
|
||||
"});
|
||||
// once all multi-cursors are at the suggested
|
||||
// indent level, they all insert a soft tab together.
|
||||
// test when all cursors are at suggested indent then tab is inserted
|
||||
cx.update_editor(|e, window, cx| e.tab(&Tab, window, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
ˇ
|
||||
|
@ -2929,6 +2928,112 @@ async fn test_tab_in_leading_whitespace_auto_indents_lines(cx: &mut TestAppConte
|
|||
);
|
||||
"});
|
||||
|
||||
// test when current indent is less than suggested indent,
|
||||
// we adjust line to match suggested indent and move cursor to it
|
||||
//
|
||||
// when no other cursor is at word boundary, all of them should move
|
||||
cx.set_state(indoc! {"
|
||||
const a: B = (
|
||||
c(
|
||||
d(
|
||||
ˇ
|
||||
ˇ )
|
||||
ˇ )
|
||||
);
|
||||
"});
|
||||
cx.update_editor(|e, window, cx| e.tab(&Tab, window, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
const a: B = (
|
||||
c(
|
||||
d(
|
||||
ˇ
|
||||
ˇ)
|
||||
ˇ)
|
||||
);
|
||||
"});
|
||||
|
||||
// test when current indent is less than suggested indent,
|
||||
// we adjust line to match suggested indent and move cursor to it
|
||||
//
|
||||
// when some other cursor is at word boundary, it should not move
|
||||
cx.set_state(indoc! {"
|
||||
const a: B = (
|
||||
c(
|
||||
d(
|
||||
ˇ
|
||||
ˇ )
|
||||
ˇ)
|
||||
);
|
||||
"});
|
||||
cx.update_editor(|e, window, cx| e.tab(&Tab, window, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
const a: B = (
|
||||
c(
|
||||
d(
|
||||
ˇ
|
||||
ˇ)
|
||||
ˇ)
|
||||
);
|
||||
"});
|
||||
|
||||
// test when current indent is more than suggested indent,
|
||||
// we just move cursor to current indent instead of suggested indent
|
||||
//
|
||||
// when no other cursor is at word boundary, all of them should move
|
||||
cx.set_state(indoc! {"
|
||||
const a: B = (
|
||||
c(
|
||||
d(
|
||||
ˇ
|
||||
ˇ )
|
||||
ˇ )
|
||||
);
|
||||
"});
|
||||
cx.update_editor(|e, window, cx| e.tab(&Tab, window, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
const a: B = (
|
||||
c(
|
||||
d(
|
||||
ˇ
|
||||
ˇ)
|
||||
ˇ)
|
||||
);
|
||||
"});
|
||||
cx.update_editor(|e, window, cx| e.tab(&Tab, window, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
const a: B = (
|
||||
c(
|
||||
d(
|
||||
ˇ
|
||||
ˇ)
|
||||
ˇ)
|
||||
);
|
||||
"});
|
||||
|
||||
// test when current indent is more than suggested indent,
|
||||
// we just move cursor to current indent instead of suggested indent
|
||||
//
|
||||
// when some other cursor is at word boundary, it doesn't move
|
||||
cx.set_state(indoc! {"
|
||||
const a: B = (
|
||||
c(
|
||||
d(
|
||||
ˇ
|
||||
ˇ )
|
||||
ˇ)
|
||||
);
|
||||
"});
|
||||
cx.update_editor(|e, window, cx| e.tab(&Tab, window, cx));
|
||||
cx.assert_editor_state(indoc! {"
|
||||
const a: B = (
|
||||
c(
|
||||
d(
|
||||
ˇ
|
||||
ˇ)
|
||||
ˇ)
|
||||
);
|
||||
"});
|
||||
|
||||
// handle auto-indent when there are multiple cursors on the same line
|
||||
cx.set_state(indoc! {"
|
||||
const a: B = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue