Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
markdown: Don't adjust indentation when inserting with multiple cursors (#40794)
vipex9ae77ec3c9fb
diff --git a/Cargo.lock b/Cargo.lockindex 5078c79e21c..87557afcb1b 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.tomlindex 2aa02e293dd..736916ebbf7 100644--- a/crates/editor/Cargo.toml+++ b/crates/editor/Cargo.toml@@ -118,6 +118,7 @@ tree-sitter-rust.workspace = truetree-sitter-typescript.workspace = truetree-sitter-yaml.workspace = truetree-sitter-bash.workspace = true+tree-sitter-md.workspace = trueunindent.workspace = trueutil = { 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.rsindex 64c335e2e4b..7ab3dcc2345 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.tomlindex 36071cb5392..2bbda0ef43e 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 = falseauto_indent_using_last_non_empty_line = falsetab_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.scmnew file mode 100644index 00000000000..7fde3226bbb--- /dev/null+++ b/crates/languages/src/markdown/indents.scm@@ -0,0 +1,3 @@+(list (list_item) @indent)++(list_item (list) @indent)