Introduce Editor::insert_flaps and Editor::remove_flaps (#12096)

This pull request introduces the ability to add flaps, custom foldable
regions whose first foldable line can be associated with:

- A toggle in the gutter
- A trailer showed at the end of the line, before the inline blame
information


https://github.com/zed-industries/zed/assets/482957/c53a9148-f31a-4743-af64-18afa73c404c

To achieve this, we changed `FoldMap::fold` to accept a piece of text to
display when the range is folded. We use this capability in flaps to
avoid displaying the ellipsis character.

We want to use this new API in the assistant to fold context while still
giving visual cues as to what that context is.

Release Notes:

- N/A

---------

Co-authored-by: Nathan Sobo <nathan@zed.dev>
Co-authored-by: Mikayla <mikayla@zed.dev>
Co-authored-by: Max <max@zed.dev>
This commit is contained in:
Antonio Scandurra 2024-05-21 20:23:37 +02:00 committed by GitHub
parent b89f360199
commit f3710877f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 868 additions and 239 deletions

View file

@ -49,6 +49,7 @@ where
&self.position
}
#[track_caller]
pub fn end(&self, cx: &<T::Summary as Summary>::Context) -> D {
if let Some(item_summary) = self.item_summary() {
let mut end = self.start().clone();
@ -59,6 +60,7 @@ where
}
}
#[track_caller]
pub fn item(&self) -> Option<&'a T> {
self.assert_did_seek();
if let Some(entry) = self.stack.last() {
@ -77,6 +79,7 @@ where
}
}
#[track_caller]
pub fn item_summary(&self) -> Option<&'a T::Summary> {
self.assert_did_seek();
if let Some(entry) = self.stack.last() {
@ -97,6 +100,7 @@ where
}
}
#[track_caller]
pub fn next_item(&self) -> Option<&'a T> {
self.assert_did_seek();
if let Some(entry) = self.stack.last() {
@ -119,6 +123,7 @@ where
}
}
#[track_caller]
fn next_leaf(&self) -> Option<&'a SumTree<T>> {
for entry in self.stack.iter().rev().skip(1) {
if entry.index < entry.tree.0.child_trees().len() - 1 {
@ -133,6 +138,7 @@ where
None
}
#[track_caller]
pub fn prev_item(&self) -> Option<&'a T> {
self.assert_did_seek();
if let Some(entry) = self.stack.last() {
@ -155,6 +161,7 @@ where
}
}
#[track_caller]
fn prev_leaf(&self) -> Option<&'a SumTree<T>> {
for entry in self.stack.iter().rev().skip(1) {
if entry.index != 0 {
@ -169,10 +176,12 @@ where
None
}
#[track_caller]
pub fn prev(&mut self, cx: &<T::Summary as Summary>::Context) {
self.prev_internal(|_| true, cx)
}
#[track_caller]
fn prev_internal<F>(&mut self, mut filter_node: F, cx: &<T::Summary as Summary>::Context)
where
F: FnMut(&T::Summary) -> bool,
@ -238,10 +247,12 @@ where
}
}
#[track_caller]
pub fn next(&mut self, cx: &<T::Summary as Summary>::Context) {
self.next_internal(|_| true, cx)
}
#[track_caller]
fn next_internal<F>(&mut self, mut filter_node: F, cx: &<T::Summary as Summary>::Context)
where
F: FnMut(&T::Summary) -> bool,
@ -329,6 +340,7 @@ where
debug_assert!(self.stack.is_empty() || self.stack.last().unwrap().tree.0.is_leaf());
}
#[track_caller]
fn assert_did_seek(&self) {
assert!(
self.did_seek,
@ -342,6 +354,7 @@ where
T: Item,
D: Dimension<'a, T::Summary>,
{
#[track_caller]
pub fn seek<Target>(
&mut self,
pos: &Target,
@ -355,6 +368,7 @@ where
self.seek_internal(pos, bias, &mut (), cx)
}
#[track_caller]
pub fn seek_forward<Target>(
&mut self,
pos: &Target,
@ -367,6 +381,7 @@ where
self.seek_internal(pos, bias, &mut (), cx)
}
#[track_caller]
pub fn slice<Target>(
&mut self,
end: &Target,
@ -386,10 +401,12 @@ where
slice.tree
}
#[track_caller]
pub fn suffix(&mut self, cx: &<T::Summary as Summary>::Context) -> SumTree<T> {
self.slice(&End::new(), Bias::Right, cx)
}
#[track_caller]
pub fn summary<Target, Output>(
&mut self,
end: &Target,
@ -406,6 +423,7 @@ where
}
/// Returns whether we found the item you where seeking for
#[track_caller]
fn seek_internal(
&mut self,
target: &dyn SeekTarget<'a, T::Summary, D>,