WIP: Add keybinding to open buffers under cursors

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-01-07 16:12:50 +01:00
parent cf62d26ed8
commit 3cab32d201
7 changed files with 70 additions and 15 deletions

View file

@ -689,6 +689,33 @@ impl MultiBuffer {
.map_or(Vec::new(), |state| state.excerpts.clone())
}
pub fn excerpted_buffers<'a, T: ToOffset>(
&'a self,
range: Range<T>,
cx: &AppContext,
) -> Vec<(ModelHandle<Buffer>, Range<usize>)> {
let snapshot = self.snapshot(cx);
let start = range.start.to_offset(&snapshot);
let end = range.end.to_offset(&snapshot);
let mut result = Vec::new();
let mut cursor = snapshot.excerpts.cursor::<usize>();
cursor.seek(&start, Bias::Right, &());
while let Some(excerpt) = cursor.item() {
if *cursor.start() > end {
break;
}
let excerpt_start = excerpt.range.start.to_offset(&excerpt.buffer);
let start = excerpt_start + (cmp::max(start, *cursor.start()) - *cursor.start());
let end = excerpt_start + (cmp::min(end, cursor.end(&())) - *cursor.start());
let buffer = self.buffers.borrow()[&excerpt.buffer_id].buffer.clone();
result.push((buffer, start..end));
}
result
}
pub fn remove_excerpts<'a>(
&mut self,
excerpt_ids: impl IntoIterator<Item = &'a ExcerptId>,