mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-02 16:33:05 +00:00
Clip anchors created on MultiBuffer's trailing newlines or headers
This commit is contained in:
parent
1b67f19edc
commit
2d1ff8f606
1 changed files with 7 additions and 2 deletions
|
@ -1080,9 +1080,14 @@ impl MultiBufferSnapshot {
|
|||
let mut cursor = self.excerpts.cursor::<(usize, Option<&ExcerptId>)>();
|
||||
cursor.seek(&offset, bias, &());
|
||||
if let Some(excerpt) = cursor.item() {
|
||||
let overshoot =
|
||||
(offset - cursor.start().0).saturating_sub(excerpt.header_height as usize);
|
||||
let start_after_header = cursor.start().0 + excerpt.header_height as usize;
|
||||
let mut end_before_newline = cursor.end(&()).0;
|
||||
if excerpt.has_trailing_newline {
|
||||
end_before_newline -= 1;
|
||||
}
|
||||
|
||||
let buffer_start = excerpt.range.start.to_offset(&excerpt.buffer);
|
||||
let overshoot = cmp::min(offset, end_before_newline).saturating_sub(start_after_header);
|
||||
Anchor {
|
||||
excerpt_id: excerpt.id.clone(),
|
||||
text_anchor: excerpt.buffer.anchor_at(buffer_start + overshoot, bias),
|
||||
|
|
Loading…
Reference in a new issue