documents: edits read the caret off a CRLF split
CI / platforms (windows-latest) (push) Failing after 10s
CI / site (push) Successful in 22s
CI / crate (push) Failing after 11m47s
CI / platforms (ubuntu-24.04) (push) Canceled after 0s

The editor splits lines on LF only, so End can leave the caret
between CR and LF. The edit runner and table insert now settle the
selection before the CR; the line helpers assert they never see a
split instead of guessing.

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-14 15:56:17 -04:00
1 parent ce015e7b7b
commit 6b033f3eb0
5 files changed
+52 -11

No files matched your search

+10 -3
View File
@@ -6,7 +6,7 @@ use gpui::{AppContext as _, Context};
use super::{
DocumentEvent, LARGEST_READ, MarkdownDocument,
block::{self, BlockCommand},
block::{self, BlockCommand, settled},
format::{Change, EditRefusal, InlineFormat, toggle},
tables::{self, TableEdit},
};
@@ -109,7 +109,8 @@ impl MarkdownDocument {
fn snapshot(&self, cx: &Context<Self>) -> Snapshot {
let text = self.editor.read(cx).text();
let Some(open) = &self.open else {
return (text.to_string(), 0, self.editor.read(cx).primary().range());
let picked = self.editor.read(cx).primary().range();
return settle((text.to_string(), 0, picked));
};
let input = open.input.read(cx);
let (before, after) = match open.append {
@@ -122,7 +123,7 @@ impl MarkdownDocument {
let picked = input.selection();
let offset = before.len();
let full = format!("{before}{}{after}", input.text());
(full, offset, offset + picked.start..offset + picked.end)
settle((full, offset, offset + picked.start..offset + picked.end))
}
/// Writes `change`: into the open block while it stays inside.
@@ -179,3 +180,9 @@ impl MarkdownDocument {
Ok(())
}
}
/// The editor splits lines on LF only; reads start off a CRLF.
fn settle((full, offset, picked): Snapshot) -> Snapshot {
let picked = settled(&full, picked.start)..settled(&full, picked.end);
(full, offset, picked)
}