Allow folding buffers inside multi buffers (#22046)
Closes https://github.com/zed-industries/zed/issues/4925 https://github.com/user-attachments/assets/e7b87375-893f-41ae-a2d9-d501499e40d1 Allows to fold any buffer inside multi buffers, either by clicking the chevron icon on the header, or by using `editor::Fold`/`editor::UnfoldLines`/`editor::ToggleFold`/`editor::FoldAll` and `editor::UnfoldAll` actions inside the multi buffer (those were noop there before). Every fold has a fake line inside it, so it's possible to navigate into that via the keyboard and unfold it with the corresponding editor action. The state is synchronized with the outline panel state: any fold inside multi buffer folds the corresponding file entry; any file entry fold inside the outline panel folds the corresponding buffer inside the multi buffer, any directory fold inside the outline panel folds the corresponding buffers inside the multi buffer for each nested file entry in the panel. Release Notes: - Added a possibility to fold buffers inside multi buffers --------- Co-authored-by: Antonio Scandurra <antonio@zed.dev> Co-authored-by: Max Brunsfeld <max@zed.dev> Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
co-authored by
Antonio Scandurra
Max Brunsfeld
Cole Miller
parent
f64fcedabb
commit
af50261ae2
@@ -195,6 +195,7 @@ pub struct ExcerptInfo {
|
||||
pub buffer: BufferSnapshot,
|
||||
pub buffer_id: BufferId,
|
||||
pub range: ExcerptRange<text::Anchor>,
|
||||
pub text_summary: TextSummary,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for ExcerptInfo {
|
||||
@@ -1546,6 +1547,33 @@ impl MultiBuffer {
|
||||
excerpts
|
||||
}
|
||||
|
||||
pub fn excerpt_ranges_for_buffer(
|
||||
&self,
|
||||
buffer_id: BufferId,
|
||||
cx: &AppContext,
|
||||
) -> Vec<Range<Point>> {
|
||||
let snapshot = self.read(cx);
|
||||
let buffers = self.buffers.borrow();
|
||||
let mut cursor = snapshot.excerpts.cursor::<(Option<&Locator>, Point)>(&());
|
||||
buffers
|
||||
.get(&buffer_id)
|
||||
.into_iter()
|
||||
.flat_map(|state| &state.excerpts)
|
||||
.filter_map(move |locator| {
|
||||
cursor.seek_forward(&Some(locator), Bias::Left, &());
|
||||
cursor.item().and_then(|excerpt| {
|
||||
if excerpt.locator == *locator {
|
||||
let excerpt_start = cursor.start().1;
|
||||
let excerpt_end = excerpt_start + excerpt.text_summary.lines;
|
||||
Some(excerpt_start..excerpt_end)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn excerpt_buffer_ids(&self) -> Vec<BufferId> {
|
||||
self.snapshot
|
||||
.borrow()
|
||||
@@ -3559,6 +3587,7 @@ impl MultiBufferSnapshot {
|
||||
buffer: excerpt.buffer.clone(),
|
||||
buffer_id: excerpt.buffer_id,
|
||||
range: excerpt.range.clone(),
|
||||
text_summary: excerpt.text_summary.clone(),
|
||||
});
|
||||
|
||||
if next.is_none() {
|
||||
@@ -3574,6 +3603,7 @@ impl MultiBufferSnapshot {
|
||||
buffer: prev_excerpt.buffer.clone(),
|
||||
buffer_id: prev_excerpt.buffer_id,
|
||||
range: prev_excerpt.range.clone(),
|
||||
text_summary: prev_excerpt.text_summary.clone(),
|
||||
});
|
||||
let row = MultiBufferRow(cursor.start().1.row);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user