Invalidate copilot suggestion on backspaces

Restore an observation on initialization

co-authored-by: antonio <antonio@zed.dev>
This commit is contained in:
Mikayla Maki 2023-04-05 08:48:39 -07:00
parent e2c690cece
commit b585470518
4 changed files with 103 additions and 1 deletions

View file

@ -1,4 +1,7 @@
use crate::{BufferSnapshot, Point, PointUtf16, TextDimension, ToOffset, ToPoint, ToPointUtf16};
use crate::{
locator::Locator, BufferSnapshot, Point, PointUtf16, TextDimension, ToOffset, ToPoint,
ToPointUtf16,
};
use anyhow::Result;
use std::{cmp::Ordering, fmt::Debug, ops::Range};
use sum_tree::Bias;
@ -86,6 +89,20 @@ impl Anchor {
{
content.summary_for_anchor(self)
}
/// Returns true when the [Anchor] is located inside a visible fragment.
pub fn is_valid(&self, buffer: &BufferSnapshot) -> bool {
if *self == Anchor::MIN || *self == Anchor::MAX {
true
} else {
let fragment_id = buffer.fragment_id_for_anchor(self);
let mut fragment_cursor = buffer.fragments.cursor::<(Option<&Locator>, usize)>();
fragment_cursor.seek(&Some(fragment_id), Bias::Left, &None);
fragment_cursor
.item()
.map_or(false, |fragment| fragment.visible)
}
}
}
pub trait OffsetRangeExt {