diff --git a/Cargo.lock b/Cargo.lock index 5078c79e21ce1a580a6e055a7ce8ab4295f56906..87557afcb1b868cf9321bc0a4746e92687bb456d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5405,6 +5405,7 @@ dependencies = [ "tree-sitter-bash", "tree-sitter-c", "tree-sitter-html", + "tree-sitter-md", "tree-sitter-python", "tree-sitter-rust", "tree-sitter-typescript", diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index 2aa02e293dd44d5fdd920ac8cd98da48b9c1a912..736916ebbf74f20f11e8c03a0e584bd8ae92e07d 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -118,6 +118,7 @@ tree-sitter-rust.workspace = true tree-sitter-typescript.workspace = true tree-sitter-yaml.workspace = true tree-sitter-bash.workspace = true +tree-sitter-md.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 64c335e2e4b0dc660efe1b28bb87984fba8aafb4..7ab3dcc2345dd8a140b7c4762dc5afadb9cef484 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -27498,6 +27498,65 @@ async fn test_paste_url_from_other_app_creates_markdown_link_over_selected_text( )); } +#[gpui::test] +async fn test_markdown_list_indent_with_multi_cursor(cx: &mut gpui::TestAppContext) { + init_test(cx, |_| {}); + + let markdown_language = languages::language("markdown", tree_sitter_md::LANGUAGE.into()); + let mut cx = EditorTestContext::new(cx).await; + + cx.update_buffer(|buffer, cx| buffer.set_language(Some(markdown_language), cx)); + + cx.set_state(&indoc! {" + - [ ] Item 1 + - [ ] Item 1.a + - [ˇ] Item 2 + - [ˇ] Item 2.a + - [ˇ] Item 2.b + " + }); + + cx.update_editor(|editor, window, cx| { + editor.handle_input("X", window, cx); + }); + + cx.assert_editor_state(indoc! {" + - [ ] Item 1 + - [ ] Item 1.a + - [Xˇ] Item 2 + - [Xˇ] Item 2.a + - [Xˇ] Item 2.b + " + }); +} + +#[gpui::test] +async fn test_markdown_list_indent_with_newline(cx: &mut gpui::TestAppContext) { + init_test(cx, |_| {}); + + let markdown_language = languages::language("markdown", tree_sitter_md::LANGUAGE.into()); + let mut cx = EditorTestContext::new(cx).await; + + cx.update_buffer(|buffer, cx| buffer.set_language(Some(markdown_language), cx)); + + cx.set_state(indoc! {" + - [x] list item + - [x] sub list itemˇ + " + }); + + cx.update_editor(|editor, window, cx| { + editor.newline(&Newline, window, cx); + }); + + cx.assert_editor_state(indoc! {" + - [x] list item + - [x] sub list item + ˇ + " + }); +} + #[gpui::test] async fn test_paste_url_from_zed_copy_creates_markdown_link_over_selected_text( cx: &mut gpui::TestAppContext, diff --git a/crates/languages/src/markdown/config.toml b/crates/languages/src/markdown/config.toml index 36071cb5392462a51c10e0513b39979580ec67f5..2bbda0ef43e9a49b483dbe22cdf0473c8fbcf73c 100644 --- a/crates/languages/src/markdown/config.toml +++ b/crates/languages/src/markdown/config.toml @@ -24,4 +24,5 @@ rewrap_prefixes = [ auto_indent_on_paste = false auto_indent_using_last_non_empty_line = false tab_size = 2 +decrease_indent_pattern = "^\\s*$" prettier_parser_name = "markdown" diff --git a/crates/languages/src/markdown/indents.scm b/crates/languages/src/markdown/indents.scm new file mode 100644 index 0000000000000000000000000000000000000000..7fde3226bbbeb0fb9f0f7a1d90a328923a5228b3 --- /dev/null +++ b/crates/languages/src/markdown/indents.scm @@ -0,0 +1,3 @@ +(list (list_item) @indent) + +(list_item (list) @indent)