Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Preserve Markdown emphasis delimiters when joining lines (#61298)
Xin Zhao9ca3f21adaba
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 8cbbba449e8..276c083dd15 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -5552,24 +5552,36 @@ impl Editor {.documentation_comment().map(|c| c.prefix.as_ref()).filter(|p| !p.is_empty());- let all_prefixes = language_scope+ let comment_prefixes = language_scope.line_comment_prefixes().iter().map(|p| p.as_ref()).chain(block_prefix).chain(doc_prefix)- .chain(language_scope.unordered_list().iter().map(|p| p.as_ref()));+ .map(|prefix| (prefix, false));+ let all_prefixes = comment_prefixes.chain(+ language_scope+ .unordered_list()+ .iter()+ .map(|prefix| (prefix.as_ref(), true)),+ );let mut longest_prefix_len = None;- for prefix in all_prefixes {+ for (prefix, is_unordered_list) in all_prefixes {let trimmed = prefix.trim_end();- if line_text_after_indent.starts_with(trimmed) {- let candidate_len =- if line_text_after_indent.starts_with(prefix) {- prefix.len()- } else {- trimmed.len()- };+ let matches_full_prefix =+ line_text_after_indent.starts_with(prefix);+ let nextline_is_bare_prefix = line_text_after_indent == trimmed;+ if matches_full_prefix+ || (!is_unordered_list+ && line_text_after_indent.starts_with(trimmed))+ || nextline_is_bare_prefix+ {+ let candidate_len = if matches_full_prefix {+ prefix.len()+ } else {+ trimmed.len()+ };if longest_prefix_len.map_or(true, |len| candidate_len > len) {longest_prefix_len = Some(candidate_len);}diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex 318495c07b3..015e8b5b43c 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -6681,6 +6681,24 @@ async fn test_join_lines_strips_comment_prefix(cx: &mut TestAppContext) {+ fooˇ bar"});+ cx.set_state(indoc! {"+ fooˇ+ *bar*+ "});+ cx.update_editor(|e, window, cx| e.join_lines(&JoinLines, window, cx));+ cx.assert_editor_state(indoc! {"+ fooˇ *bar*+ "});++ cx.set_state(indoc! {"+ * ˇfoo+ *+ "});+ cx.update_editor(|e, window, cx| e.join_lines(&JoinLines, window, cx));+ cx.assert_editor_state(indoc! {"+ * fooˇ+ "});+// No-whitespace join also strips the list marker.cx.set_state(indoc! {"- ˇfoo