diff --git a/src/documents/document/tests/point.rs b/src/documents/document/tests/point.rs index 5d42434..0bc3089 100644 --- a/src/documents/document/tests/point.rs +++ b/src/documents/document/tests/point.rs @@ -89,6 +89,17 @@ fn a_press_opens_the_block_at_the_pressed_character(cx: &mut TestAppContext) { ); } +#[gpui::test] +fn a_press_past_a_crlf_line_types_before_its_end(cx: &mut TestAppContext) { + let source = "one\r\ntwo\r\n"; + let (document, cx) = open(source, MarkdownMode::Visual, cx); + press_on(0, 3, MouseButton::Left, cx); + assert_eq!(opened_caret(&document, cx), "one".len()); + cx.simulate_input("X"); + cx.simulate_keystrokes("escape"); + assert_eq!(super::text(&document, cx), "oneX\r\ntwo\r\n"); +} + #[gpui::test] fn a_secondary_press_moves_the_caret_and_opens_nothing(cx: &mut TestAppContext) { let (document, cx) = open(TEXT, MarkdownMode::Visual, cx); diff --git a/src/documents/tree/mod.rs b/src/documents/tree/mod.rs index 1bd800d..35f5cc4 100644 --- a/src/documents/tree/mod.rs +++ b/src/documents/tree/mod.rs @@ -180,7 +180,7 @@ pub fn parse(markdown: &str) -> Vec { } impl<'a> Reader<'a> { - /// A reader of `root`, parsed from `source`, as the screen draws it. + /// Reads `root`, parsed from `source`, as drawn on screen. pub fn new(source: &'a str, root: &mdast::Node) -> Self { Self::reading(source, root, true) } diff --git a/src/documents/tree/sources.rs b/src/documents/tree/sources.rs index a65a953..7f8f6e9 100644 --- a/src/documents/tree/sources.rs +++ b/src/documents/tree/sources.rs @@ -319,12 +319,8 @@ fn aligned(drawn: &str, written: &str, escapes: Escapes) -> Vec<(usize, usize)> let Some(s) = source[..j].last() else { return out; }; - if d == s.ch { - j -= 1; - break s.at; - } - // A join: a line's end drawn as white space. - if d.is_whitespace() && s.ends_line() { + // A line's end, drawn or joined; CRLF is one end. + if d == s.ch || (d.is_whitespace() && s.ends_line()) { j -= 1; if s.ch == '\n' && j > 0 && source[j - 1].ch == '\r' && source[j - 1].raw == s.raw { j -= 1; @@ -393,6 +389,15 @@ mod tests { assert_eq!(under(source, "next"), source.find("next").unwrap()); } + #[test] + fn a_drawn_crlf_reads_back_to_its_start() { + let source = "one\r\ntwo"; + let inline = first(source); + let end = inline.text.find('\n').expect("a drawn line end"); + assert_eq!(inline.source_at(source, end), Some(3)); + assert_eq!(under(source, "two"), source.find("two").unwrap()); + } + #[test] fn joins_escapes_and_indents_read_back() { let source = "a \\*star\\* x\n y";