Documents: a CRLF drawn as two chars reads back char for char
Only a CRLF the drawn text collapses is one end; inline code keeps both. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c31d092583
commit
26af4be04f
2 files changed
+23
-2
No files matched your search
@@ -100,6 +100,14 @@ fn a_press_past_a_crlf_line_types_before_its_end(cx: &mut TestAppContext) {
|
||||
assert_eq!(super::text(&document, cx), "oneX\r\ntwo\r\n");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_press_in_code_keeping_a_crlf_lands_on_its_character(cx: &mut TestAppContext) {
|
||||
let source = "`one\r\ntwo`\n";
|
||||
let (document, cx) = open(source, MarkdownMode::Visual, cx);
|
||||
press_on(0, 2, MouseButton::Left, cx);
|
||||
assert_eq!(opened_caret(&document, cx), "`on".len());
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_secondary_press_moves_the_caret_and_opens_nothing(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open(TEXT, MarkdownMode::Visual, cx);
|
||||
|
||||
@@ -319,10 +319,16 @@ fn aligned(drawn: &str, written: &str, escapes: Escapes) -> Vec<(usize, usize)>
|
||||
let Some(s) = source[..j].last() else {
|
||||
return out;
|
||||
};
|
||||
// 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 {
|
||||
// A CRLF drawn as one char is one end.
|
||||
let collapsed = !drawn[..byte].ends_with('\r');
|
||||
if collapsed
|
||||
&& s.ch == '\n'
|
||||
&& j > 0
|
||||
&& source[j - 1].ch == '\r'
|
||||
&& source[j - 1].raw == s.raw
|
||||
{
|
||||
j -= 1;
|
||||
}
|
||||
break source[j].at;
|
||||
@@ -398,6 +404,13 @@ mod tests {
|
||||
assert_eq!(under(source, "two"), source.find("two").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_kept_crlf_reads_back_char_for_char() {
|
||||
let source = "`one\r\ntwo`\n";
|
||||
assert_eq!(under(source, "ne"), source.find("ne").unwrap());
|
||||
assert_eq!(under(source, "two"), source.find("two").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn joins_escapes_and_indents_read_back() {
|
||||
let source = "a \\*star\\* x\n y";
|
||||
|
||||
Reference in new issue
Block a user