Documents: a drawn CRLF reads back to its start
CI / platforms (windows-latest) (push) Failing after 10s
CI / site (push) Successful in 23s
CI / crate (push) Failing after 10m55s
CI / platforms (ubuntu-24.04) (push) Canceled after 0s

A press at a CRLF line's end typed between CR and LF.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-15 13:04:25 -04:00
1 parent 5954132e76
commit c31d092583
3 files changed
+23 -7

No files matched your search

+11
View File
@@ -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] #[gpui::test]
fn a_secondary_press_moves_the_caret_and_opens_nothing(cx: &mut TestAppContext) { fn a_secondary_press_moves_the_caret_and_opens_nothing(cx: &mut TestAppContext) {
let (document, cx) = open(TEXT, MarkdownMode::Visual, cx); let (document, cx) = open(TEXT, MarkdownMode::Visual, cx);
+1 -1
View File
@@ -180,7 +180,7 @@ pub fn parse(markdown: &str) -> Vec<Node> {
} }
impl<'a> Reader<'a> { 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 { pub fn new(source: &'a str, root: &mdast::Node) -> Self {
Self::reading(source, root, true) Self::reading(source, root, true)
} }
+11 -6
View File
@@ -319,12 +319,8 @@ fn aligned(drawn: &str, written: &str, escapes: Escapes) -> Vec<(usize, usize)>
let Some(s) = source[..j].last() else { let Some(s) = source[..j].last() else {
return out; return out;
}; };
if d == s.ch { // A line's end, drawn or joined; CRLF is one end.
j -= 1; if d == s.ch || (d.is_whitespace() && s.ends_line()) {
break s.at;
}
// A join: a line's end drawn as white space.
if d.is_whitespace() && s.ends_line() {
j -= 1; j -= 1;
if s.ch == '\n' && j > 0 && source[j - 1].ch == '\r' && source[j - 1].raw == s.raw { if s.ch == '\n' && j > 0 && source[j - 1].ch == '\r' && source[j - 1].raw == s.raw {
j -= 1; j -= 1;
@@ -393,6 +389,15 @@ mod tests {
assert_eq!(under(source, "next"), source.find("next").unwrap()); 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] #[test]
fn joins_escapes_and_indents_read_back() { fn joins_escapes_and_indents_read_back() {
let source = "a \\*star\\* x\n y"; let source = "a \\*star\\* x\n y";