documents: a caret inside CRLF reads as its line's end
The code editor splits lines on LF only, so End and Right can leave the caret between CR and LF. line_start and line_end now read that spot as the end of its line, so insert_table keeps CRLF around a new table. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
07fee552c3
commit
ce015e7b7b
2 files changed
+26
No files matched your search
@@ -251,11 +251,19 @@ fn path<'a>(text: &str, root: &'a Node, at: usize) -> Vec<&'a Node> {
|
||||
path
|
||||
}
|
||||
|
||||
/// `at`, before the CR when it splits a CRLF.
|
||||
fn settled(text: &str, at: usize) -> usize {
|
||||
let split = text[..at].ends_with('\r') && text[at..].starts_with('\n');
|
||||
if split { at - 1 } else { at }
|
||||
}
|
||||
|
||||
pub(super) fn line_start(text: &str, at: usize) -> usize {
|
||||
let at = settled(text, at);
|
||||
text[..at].rfind(['\n', '\r']).map_or(0, |at| at + 1)
|
||||
}
|
||||
|
||||
pub(super) fn line_end(text: &str, at: usize) -> usize {
|
||||
let at = settled(text, at);
|
||||
at + text[at..].find(['\n', '\r']).unwrap_or(text.len() - at)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user