Allow edits at the end of MultiBuffer
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
7bbaa1d930
commit
bcdb4ffd88
2 changed files with 7 additions and 1 deletions
|
@ -1254,7 +1254,7 @@ mod tests {
|
||||||
let buffer = if rng.gen() {
|
let buffer = if rng.gen() {
|
||||||
MultiBuffer::build_simple(&text, cx)
|
MultiBuffer::build_simple(&text, cx)
|
||||||
} else {
|
} else {
|
||||||
MultiBuffer::build_random(1, &mut rng, cx)
|
MultiBuffer::build_random(rng.gen_range(1..=5), &mut rng, cx)
|
||||||
};
|
};
|
||||||
let mut buffer_snapshot = buffer.read(cx).snapshot(cx);
|
let mut buffer_snapshot = buffer.read(cx).snapshot(cx);
|
||||||
let mut map = FoldMap::new(buffer_snapshot.clone()).0;
|
let mut map = FoldMap::new(buffer_snapshot.clone()).0;
|
||||||
|
|
|
@ -305,6 +305,9 @@ impl MultiBuffer {
|
||||||
let start = range.start.to_offset(&snapshot);
|
let start = range.start.to_offset(&snapshot);
|
||||||
let end = range.end.to_offset(&snapshot);
|
let end = range.end.to_offset(&snapshot);
|
||||||
cursor.seek(&start, Bias::Right, &());
|
cursor.seek(&start, Bias::Right, &());
|
||||||
|
if cursor.item().is_none() && start == *cursor.start() {
|
||||||
|
cursor.prev(&());
|
||||||
|
}
|
||||||
let start_excerpt = cursor.item().expect("start offset out of bounds");
|
let start_excerpt = cursor.item().expect("start offset out of bounds");
|
||||||
let start_overshoot =
|
let start_overshoot =
|
||||||
(start - cursor.start()).saturating_sub(start_excerpt.header_height as usize);
|
(start - cursor.start()).saturating_sub(start_excerpt.header_height as usize);
|
||||||
|
@ -312,6 +315,9 @@ impl MultiBuffer {
|
||||||
start_excerpt.range.start.to_offset(&start_excerpt.buffer) + start_overshoot;
|
start_excerpt.range.start.to_offset(&start_excerpt.buffer) + start_overshoot;
|
||||||
|
|
||||||
cursor.seek(&end, Bias::Right, &());
|
cursor.seek(&end, Bias::Right, &());
|
||||||
|
if cursor.item().is_none() && end == *cursor.start() {
|
||||||
|
cursor.prev(&());
|
||||||
|
}
|
||||||
let end_excerpt = cursor.item().expect("end offset out of bounds");
|
let end_excerpt = cursor.item().expect("end offset out of bounds");
|
||||||
let end_overshoot =
|
let end_overshoot =
|
||||||
(end - cursor.start()).saturating_sub(end_excerpt.header_height as usize);
|
(end - cursor.start()).saturating_sub(end_excerpt.header_height as usize);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue