diff --git a/Cargo.lock b/Cargo.lock index 48928bcea0ff0fe5b9b9da256f265588e81f32ad..d7e645131d982ee10f25e5e84e558d54c0ab0b76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4830,6 +4830,7 @@ dependencies = [ "tree-sitter-python", "tree-sitter-rust", "tree-sitter-typescript", + "tree-sitter-yaml", "ui", "unicode-script", "unicode-segmentation", diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index bea83b1df826a3dac1cf4afe14a0dd7b417b972b..4d6939567eb8150883a4eb5e4e9e5b0949a421a0 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -109,6 +109,7 @@ theme = { workspace = true, features = ["test-support"] } tree-sitter-html.workspace = true tree-sitter-rust.workspace = true tree-sitter-typescript.workspace = true +tree-sitter-yaml.workspace = true unindent.workspace = true util = { workspace = true, features = ["test-support"] } workspace = { workspace = true, features = ["test-support"] } diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 8615ff2a97de676b593e46d15811ad43f1a93706..ade9a9322bcdbe38ad33fe9611820c43e2ea5809 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -3468,6 +3468,70 @@ async fn test_indent_outdent(cx: &mut TestAppContext) { "}); } +#[gpui::test] +async fn test_indent_yaml_comments_with_multiple_cursors(cx: &mut TestAppContext) { + // This is a regression test for issue #33761 + init_test(cx, |_| {}); + + let mut cx = EditorTestContext::new(cx).await; + let yaml_language = languages::language("yaml", tree_sitter_yaml::LANGUAGE.into()); + cx.update_buffer(|buffer, cx| buffer.set_language(Some(yaml_language), cx)); + + cx.set_state( + r#"ˇ# ingress: +ˇ# api: +ˇ# enabled: false +ˇ# pathType: Prefix +ˇ# console: +ˇ# enabled: false +ˇ# pathType: Prefix +"#, + ); + + // Press tab to indent all lines + cx.update_editor(|e, window, cx| e.tab(&Tab, window, cx)); + + cx.assert_editor_state( + r#" ˇ# ingress: + ˇ# api: + ˇ# enabled: false + ˇ# pathType: Prefix + ˇ# console: + ˇ# enabled: false + ˇ# pathType: Prefix +"#, + ); +} + +#[gpui::test] +async fn test_indent_yaml_non_comments_with_multiple_cursors(cx: &mut TestAppContext) { + // This is a test to make sure our fix for issue #33761 didn't break anything + init_test(cx, |_| {}); + + let mut cx = EditorTestContext::new(cx).await; + let yaml_language = languages::language("yaml", tree_sitter_yaml::LANGUAGE.into()); + cx.update_buffer(|buffer, cx| buffer.set_language(Some(yaml_language), cx)); + + cx.set_state( + r#"ˇingress: +ˇ api: +ˇ enabled: false +ˇ pathType: Prefix +"#, + ); + + // Press tab to indent all lines + cx.update_editor(|e, window, cx| e.tab(&Tab, window, cx)); + + cx.assert_editor_state( + r#"ˇingress: + ˇapi: + ˇenabled: false + ˇpathType: Prefix +"#, + ); +} + #[gpui::test] async fn test_indent_outdent_with_hard_tabs(cx: &mut TestAppContext) { init_test(cx, |settings| { diff --git a/crates/languages/src/yaml/config.toml b/crates/languages/src/yaml/config.toml index cf3d9e1181a3844987afd7b017a8c905b3bb5691..4dfb890c5481c3814722b9d143c17d7d8399b478 100644 --- a/crates/languages/src/yaml/config.toml +++ b/crates/languages/src/yaml/config.toml @@ -12,6 +12,6 @@ brackets = [ auto_indent_on_paste = false auto_indent_using_last_non_empty_line = false -increase_indent_pattern = ":\\s*[|>]?\\s*$" +increase_indent_pattern = "^[^#]*:\\s*[|>]?\\s*$" prettier_parser_name = "yaml" tab_size = 2