Fix invalid anchors in breadcrumbs (#38687)
Release Notes: - (nightly only) Fix panic when your cursor abuts a multibyte character
This commit is contained in:
@@ -3756,11 +3756,9 @@ impl BufferSnapshot {
|
||||
theme: Option<&SyntaxTheme>,
|
||||
) -> Vec<OutlineItem<Anchor>> {
|
||||
let position = position.to_offset(self);
|
||||
let mut items = self.outline_items_containing(
|
||||
position.saturating_sub(1)..self.len().min(position + 1),
|
||||
false,
|
||||
theme,
|
||||
);
|
||||
let start = self.clip_offset(position.saturating_sub(1), Bias::Left);
|
||||
let end = self.clip_offset(position + 1, Bias::Right);
|
||||
let mut items = self.outline_items_containing(start..end, false, theme);
|
||||
let mut prev_depth = None;
|
||||
items.retain(|item| {
|
||||
let result = prev_depth.is_none_or(|prev_depth| item.depth > prev_depth);
|
||||
|
||||
@@ -1052,6 +1052,21 @@ async fn test_symbols_containing(cx: &mut gpui::TestAppContext) {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
let (text, offsets) = marked_text_offsets(
|
||||
&"
|
||||
// ˇ😅 //
|
||||
fn test() {
|
||||
}
|
||||
"
|
||||
.unindent(),
|
||||
);
|
||||
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
|
||||
let snapshot = buffer.update(cx, |buffer, _| buffer.snapshot());
|
||||
|
||||
// note, it would be nice to actually return the method test in this
|
||||
// case, but primarily asserting we don't crash because of the multibyte character.
|
||||
assert_eq!(snapshot.symbols_containing(offsets[0], None), vec![]);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
|
||||
Reference in New Issue
Block a user