Rename flaps to creases (#13144)

This is a simple rename and should be transparent for users.

Release Notes:

- N/A
This commit is contained in:
Antonio Scandurra 2024-06-17 16:58:59 +02:00 committed by GitHub
parent 54828ab836
commit b075ce8f04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 142 additions and 140 deletions

View file

@ -18,11 +18,11 @@ use collections::{BTreeSet, HashMap, HashSet};
use editor::actions::ShowCompletions; use editor::actions::ShowCompletions;
use editor::{ use editor::{
actions::{FoldAt, MoveToEndOfLine, Newline, UnfoldAt}, actions::{FoldAt, MoveToEndOfLine, Newline, UnfoldAt},
display_map::{BlockDisposition, BlockId, BlockProperties, BlockStyle, Flap, ToDisplayPoint}, display_map::{BlockDisposition, BlockId, BlockProperties, BlockStyle, Crease, ToDisplayPoint},
scroll::{Autoscroll, AutoscrollStrategy}, scroll::{Autoscroll, AutoscrollStrategy},
Anchor, Editor, EditorEvent, RowExt, ToOffset as _, ToPoint, Anchor, Editor, EditorEvent, RowExt, ToOffset as _, ToPoint,
}; };
use editor::{display_map::FlapId, FoldPlaceholder}; use editor::{display_map::CreaseId, FoldPlaceholder};
use file_icons::FileIcons; use file_icons::FileIcons;
use fs::Fs; use fs::Fs;
use futures::future::Shared; use futures::future::Shared;
@ -2158,7 +2158,7 @@ pub struct ContextEditor {
editor: View<Editor>, editor: View<Editor>,
blocks: HashSet<BlockId>, blocks: HashSet<BlockId>,
scroll_position: Option<ScrollPosition>, scroll_position: Option<ScrollPosition>,
pending_slash_command_flaps: HashMap<Range<language::Anchor>, FlapId>, pending_slash_command_creases: HashMap<Range<language::Anchor>, CreaseId>,
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
} }
@ -2230,7 +2230,7 @@ impl ContextEditor {
scroll_position: None, scroll_position: None,
fs, fs,
workspace: workspace.downgrade(), workspace: workspace.downgrade(),
pending_slash_command_flaps: HashMap::default(), pending_slash_command_creases: HashMap::default(),
_subscriptions, _subscriptions,
}; };
this.update_message_headers(cx); this.update_message_headers(cx);
@ -2493,14 +2493,14 @@ impl ContextEditor {
let buffer = editor.buffer().read(cx).snapshot(cx); let buffer = editor.buffer().read(cx).snapshot(cx);
let excerpt_id = *buffer.as_singleton().unwrap().0; let excerpt_id = *buffer.as_singleton().unwrap().0;
editor.remove_flaps( editor.remove_creases(
removed removed
.iter() .iter()
.filter_map(|range| self.pending_slash_command_flaps.remove(range)), .filter_map(|range| self.pending_slash_command_creases.remove(range)),
cx, cx,
); );
let flap_ids = editor.insert_flaps( let crease_ids = editor.insert_creases(
updated.iter().map(|command| { updated.iter().map(|command| {
let workspace = self.workspace.clone(); let workspace = self.workspace.clone();
let confirm_command = Arc::new({ let confirm_command = Arc::new({
@ -2546,16 +2546,16 @@ impl ContextEditor {
let end = buffer let end = buffer
.anchor_in_excerpt(excerpt_id, command.source_range.end) .anchor_in_excerpt(excerpt_id, command.source_range.end)
.unwrap(); .unwrap();
Flap::new(start..end, placeholder, render_toggle, render_trailer) Crease::new(start..end, placeholder, render_toggle, render_trailer)
}), }),
cx, cx,
); );
self.pending_slash_command_flaps.extend( self.pending_slash_command_creases.extend(
updated updated
.iter() .iter()
.map(|command| command.source_range.clone()) .map(|command| command.source_range.clone())
.zip(flap_ids), .zip(crease_ids),
); );
}) })
} }
@ -2598,7 +2598,7 @@ impl ContextEditor {
let buffer = editor.buffer().read(cx).snapshot(cx); let buffer = editor.buffer().read(cx).snapshot(cx);
let excerpt_id = *buffer.as_singleton().unwrap().0; let excerpt_id = *buffer.as_singleton().unwrap().0;
let mut buffer_rows_to_fold = BTreeSet::new(); let mut buffer_rows_to_fold = BTreeSet::new();
let mut flaps = Vec::new(); let mut creases = Vec::new();
for section in sections { for section in sections {
let start = buffer let start = buffer
.anchor_in_excerpt(excerpt_id, section.range.start) .anchor_in_excerpt(excerpt_id, section.range.start)
@ -2608,7 +2608,7 @@ impl ContextEditor {
.unwrap(); .unwrap();
let buffer_row = MultiBufferRow(start.to_point(&buffer).row); let buffer_row = MultiBufferRow(start.to_point(&buffer).row);
buffer_rows_to_fold.insert(buffer_row); buffer_rows_to_fold.insert(buffer_row);
flaps.push(Flap::new( creases.push(Crease::new(
start..end, start..end,
FoldPlaceholder { FoldPlaceholder {
render: Arc::new({ render: Arc::new({
@ -2638,7 +2638,7 @@ impl ContextEditor {
)); ));
} }
editor.insert_flaps(flaps, cx); editor.insert_creases(creases, cx);
for buffer_row in buffer_rows_to_fold.into_iter().rev() { for buffer_row in buffer_rows_to_fold.into_iter().rev() {
editor.fold_at(&FoldAt { buffer_row }, cx); editor.fold_at(&FoldAt { buffer_row }, cx);

View file

@ -18,7 +18,7 @@
//! [EditorElement]: crate::element::EditorElement //! [EditorElement]: crate::element::EditorElement
mod block_map; mod block_map;
mod flap_map; mod crease_map;
mod fold_map; mod fold_map;
mod inlay_map; mod inlay_map;
mod tab_map; mod tab_map;
@ -33,7 +33,7 @@ pub use block_map::{
}; };
use block_map::{BlockRow, BlockSnapshot}; use block_map::{BlockRow, BlockSnapshot};
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
pub use flap_map::*; pub use crease_map::*;
pub use fold_map::{Fold, FoldId, FoldPlaceholder, FoldPoint}; pub use fold_map::{Fold, FoldId, FoldPlaceholder, FoldPoint};
use fold_map::{FoldMap, FoldSnapshot}; use fold_map::{FoldMap, FoldSnapshot};
use gpui::{ use gpui::{
@ -106,7 +106,7 @@ pub struct DisplayMap {
/// Regions of inlays that should be highlighted. /// Regions of inlays that should be highlighted.
inlay_highlights: InlayHighlights, inlay_highlights: InlayHighlights,
/// A container for explicitly foldable ranges, which supersede indentation based fold range suggestions. /// A container for explicitly foldable ranges, which supersede indentation based fold range suggestions.
flap_map: FlapMap, crease_map: CreaseMap,
fold_placeholder: FoldPlaceholder, fold_placeholder: FoldPlaceholder,
pub clip_at_line_ends: bool, pub clip_at_line_ends: bool,
} }
@ -139,7 +139,7 @@ impl DisplayMap {
excerpt_header_height, excerpt_header_height,
excerpt_footer_height, excerpt_footer_height,
); );
let flap_map = FlapMap::default(); let crease_map = CreaseMap::default();
cx.observe(&wrap_map, |_, _, cx| cx.notify()).detach(); cx.observe(&wrap_map, |_, _, cx| cx.notify()).detach();
@ -151,7 +151,7 @@ impl DisplayMap {
tab_map, tab_map,
wrap_map, wrap_map,
block_map, block_map,
flap_map, crease_map,
fold_placeholder, fold_placeholder,
text_highlights: Default::default(), text_highlights: Default::default(),
inlay_highlights: Default::default(), inlay_highlights: Default::default(),
@ -178,7 +178,7 @@ impl DisplayMap {
tab_snapshot, tab_snapshot,
wrap_snapshot, wrap_snapshot,
block_snapshot, block_snapshot,
flap_snapshot: self.flap_map.snapshot(), crease_snapshot: self.crease_map.snapshot(),
text_highlights: self.text_highlights.clone(), text_highlights: self.text_highlights.clone(),
inlay_highlights: self.inlay_highlights.clone(), inlay_highlights: self.inlay_highlights.clone(),
clip_at_line_ends: self.clip_at_line_ends, clip_at_line_ends: self.clip_at_line_ends,
@ -247,22 +247,22 @@ impl DisplayMap {
self.block_map.read(snapshot, edits); self.block_map.read(snapshot, edits);
} }
pub fn insert_flaps( pub fn insert_creases(
&mut self, &mut self,
flaps: impl IntoIterator<Item = Flap>, creases: impl IntoIterator<Item = Crease>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Vec<FlapId> { ) -> Vec<CreaseId> {
let snapshot = self.buffer.read(cx).snapshot(cx); let snapshot = self.buffer.read(cx).snapshot(cx);
self.flap_map.insert(flaps, &snapshot) self.crease_map.insert(creases, &snapshot)
} }
pub fn remove_flaps( pub fn remove_creases(
&mut self, &mut self,
flap_ids: impl IntoIterator<Item = FlapId>, crease_ids: impl IntoIterator<Item = CreaseId>,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) { ) {
let snapshot = self.buffer.read(cx).snapshot(cx); let snapshot = self.buffer.read(cx).snapshot(cx);
self.flap_map.remove(flap_ids, &snapshot) self.crease_map.remove(crease_ids, &snapshot)
} }
pub fn insert_blocks( pub fn insert_blocks(
@ -472,7 +472,7 @@ pub struct HighlightedChunk<'a> {
pub struct DisplaySnapshot { pub struct DisplaySnapshot {
pub buffer_snapshot: MultiBufferSnapshot, pub buffer_snapshot: MultiBufferSnapshot,
pub fold_snapshot: FoldSnapshot, pub fold_snapshot: FoldSnapshot,
pub flap_snapshot: FlapSnapshot, pub crease_snapshot: CreaseSnapshot,
inlay_snapshot: InlaySnapshot, inlay_snapshot: InlaySnapshot,
tab_snapshot: TabSnapshot, tab_snapshot: TabSnapshot,
wrap_snapshot: WrapSnapshot, wrap_snapshot: WrapSnapshot,
@ -955,13 +955,13 @@ impl DisplaySnapshot {
buffer_row: MultiBufferRow, buffer_row: MultiBufferRow,
) -> Option<(Range<Point>, FoldPlaceholder)> { ) -> Option<(Range<Point>, FoldPlaceholder)> {
let start = MultiBufferPoint::new(buffer_row.0, self.buffer_snapshot.line_len(buffer_row)); let start = MultiBufferPoint::new(buffer_row.0, self.buffer_snapshot.line_len(buffer_row));
if let Some(flap) = self if let Some(crease) = self
.flap_snapshot .crease_snapshot
.query_row(buffer_row, &self.buffer_snapshot) .query_row(buffer_row, &self.buffer_snapshot)
{ {
Some(( Some((
flap.range.to_point(&self.buffer_snapshot), crease.range.to_point(&self.buffer_snapshot),
flap.placeholder.clone(), crease.placeholder.clone(),
)) ))
} else if self.starts_indent(MultiBufferRow(start.row)) } else if self.starts_indent(MultiBufferRow(start.row))
&& !self.is_line_folded(MultiBufferRow(start.row)) && !self.is_line_folded(MultiBufferRow(start.row))
@ -1946,7 +1946,7 @@ pub mod tests {
} }
#[gpui::test] #[gpui::test]
fn test_flaps(cx: &mut gpui::AppContext) { fn test_creases(cx: &mut gpui::AppContext) {
init_test(cx, |_| {}); init_test(cx, |_| {});
let text = "aaa\nbbb\nccc\nddd\neee\nfff\nggg\nhhh\niii\njjj\nkkk\nlll"; let text = "aaa\nbbb\nccc\nddd\neee\nfff\nggg\nhhh\niii\njjj\nkkk\nlll";
@ -1969,8 +1969,8 @@ pub mod tests {
let range = let range =
snapshot.anchor_before(Point::new(2, 0))..snapshot.anchor_after(Point::new(3, 3)); snapshot.anchor_before(Point::new(2, 0))..snapshot.anchor_after(Point::new(3, 3));
map.flap_map.insert( map.crease_map.insert(
[Flap::new( [Crease::new(
range, range,
FoldPlaceholder::test(), FoldPlaceholder::test(),
|_row, _status, _toggle, _cx| div(), |_row, _status, _toggle, _cx| div(),

View file

@ -9,36 +9,36 @@ use ui::WindowContext;
use crate::FoldPlaceholder; use crate::FoldPlaceholder;
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)] #[derive(Copy, Clone, Default, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct FlapId(usize); pub struct CreaseId(usize);
#[derive(Default)] #[derive(Default)]
pub struct FlapMap { pub struct CreaseMap {
snapshot: FlapSnapshot, snapshot: CreaseSnapshot,
next_id: FlapId, next_id: CreaseId,
id_to_range: HashMap<FlapId, Range<Anchor>>, id_to_range: HashMap<CreaseId, Range<Anchor>>,
} }
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct FlapSnapshot { pub struct CreaseSnapshot {
flaps: SumTree<FlapItem>, creases: SumTree<CreaseItem>,
} }
impl FlapSnapshot { impl CreaseSnapshot {
/// Returns the first Flap starting on the specified buffer row. /// Returns the first Crease starting on the specified buffer row.
pub fn query_row<'a>( pub fn query_row<'a>(
&'a self, &'a self,
row: MultiBufferRow, row: MultiBufferRow,
snapshot: &'a MultiBufferSnapshot, snapshot: &'a MultiBufferSnapshot,
) -> Option<&'a Flap> { ) -> Option<&'a Crease> {
let start = snapshot.anchor_before(Point::new(row.0, 0)); let start = snapshot.anchor_before(Point::new(row.0, 0));
let mut cursor = self.flaps.cursor::<ItemSummary>(); let mut cursor = self.creases.cursor::<ItemSummary>();
cursor.seek(&start, Bias::Left, snapshot); cursor.seek(&start, Bias::Left, snapshot);
while let Some(item) = cursor.item() { while let Some(item) = cursor.item() {
match Ord::cmp(&item.flap.range.start.to_point(snapshot).row, &row.0) { match Ord::cmp(&item.crease.range.start.to_point(snapshot).row, &row.0) {
Ordering::Less => cursor.next(snapshot), Ordering::Less => cursor.next(snapshot),
Ordering::Equal => { Ordering::Equal => {
if item.flap.range.start.is_valid(snapshot) { if item.crease.range.start.is_valid(snapshot) {
return Some(&item.flap); return Some(&item.crease);
} else { } else {
cursor.next(snapshot); cursor.next(snapshot);
} }
@ -49,17 +49,17 @@ impl FlapSnapshot {
return None; return None;
} }
pub fn flap_items_with_offsets( pub fn crease_items_with_offsets(
&self, &self,
snapshot: &MultiBufferSnapshot, snapshot: &MultiBufferSnapshot,
) -> Vec<(FlapId, Range<Point>)> { ) -> Vec<(CreaseId, Range<Point>)> {
let mut cursor = self.flaps.cursor::<ItemSummary>(); let mut cursor = self.creases.cursor::<ItemSummary>();
let mut results = Vec::new(); let mut results = Vec::new();
cursor.next(snapshot); cursor.next(snapshot);
while let Some(item) = cursor.item() { while let Some(item) = cursor.item() {
let start_point = item.flap.range.start.to_point(snapshot); let start_point = item.crease.range.start.to_point(snapshot);
let end_point = item.flap.range.end.to_point(snapshot); let end_point = item.crease.range.end.to_point(snapshot);
results.push((item.id, start_point..end_point)); results.push((item.id, start_point..end_point));
cursor.next(snapshot); cursor.next(snapshot);
} }
@ -82,14 +82,14 @@ type RenderTrailerFn =
Arc<dyn Send + Sync + Fn(MultiBufferRow, bool, &mut WindowContext) -> AnyElement>; Arc<dyn Send + Sync + Fn(MultiBufferRow, bool, &mut WindowContext) -> AnyElement>;
#[derive(Clone)] #[derive(Clone)]
pub struct Flap { pub struct Crease {
pub range: Range<Anchor>, pub range: Range<Anchor>,
pub placeholder: FoldPlaceholder, pub placeholder: FoldPlaceholder,
pub render_toggle: RenderToggleFn, pub render_toggle: RenderToggleFn,
pub render_trailer: RenderTrailerFn, pub render_trailer: RenderTrailerFn,
} }
impl Flap { impl Crease {
pub fn new<RenderToggle, ToggleElement, RenderTrailer, TrailerElement>( pub fn new<RenderToggle, ToggleElement, RenderTrailer, TrailerElement>(
range: Range<Anchor>, range: Range<Anchor>,
placeholder: FoldPlaceholder, placeholder: FoldPlaceholder,
@ -115,7 +115,7 @@ impl Flap {
+ 'static, + 'static,
TrailerElement: IntoElement, TrailerElement: IntoElement,
{ {
Flap { Crease {
range, range,
placeholder, placeholder,
render_toggle: Arc::new(move |row, folded, toggle, cx| { render_toggle: Arc::new(move |row, folded, toggle, cx| {
@ -128,50 +128,52 @@ impl Flap {
} }
} }
impl std::fmt::Debug for Flap { impl std::fmt::Debug for Crease {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Flap").field("range", &self.range).finish() f.debug_struct("Crease")
.field("range", &self.range)
.finish()
} }
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct FlapItem { struct CreaseItem {
id: FlapId, id: CreaseId,
flap: Flap, crease: Crease,
} }
impl FlapMap { impl CreaseMap {
pub fn snapshot(&self) -> FlapSnapshot { pub fn snapshot(&self) -> CreaseSnapshot {
self.snapshot.clone() self.snapshot.clone()
} }
pub fn insert( pub fn insert(
&mut self, &mut self,
flaps: impl IntoIterator<Item = Flap>, creases: impl IntoIterator<Item = Crease>,
snapshot: &MultiBufferSnapshot, snapshot: &MultiBufferSnapshot,
) -> Vec<FlapId> { ) -> Vec<CreaseId> {
let mut new_ids = Vec::new(); let mut new_ids = Vec::new();
self.snapshot.flaps = { self.snapshot.creases = {
let mut new_flaps = SumTree::new(); let mut new_creases = SumTree::new();
let mut cursor = self.snapshot.flaps.cursor::<ItemSummary>(); let mut cursor = self.snapshot.creases.cursor::<ItemSummary>();
for flap in flaps { for crease in creases {
new_flaps.append(cursor.slice(&flap.range, Bias::Left, snapshot), snapshot); new_creases.append(cursor.slice(&crease.range, Bias::Left, snapshot), snapshot);
let id = self.next_id; let id = self.next_id;
self.next_id.0 += 1; self.next_id.0 += 1;
self.id_to_range.insert(id, flap.range.clone()); self.id_to_range.insert(id, crease.range.clone());
new_flaps.push(FlapItem { flap, id }, snapshot); new_creases.push(CreaseItem { crease, id }, snapshot);
new_ids.push(id); new_ids.push(id);
} }
new_flaps.append(cursor.suffix(snapshot), snapshot); new_creases.append(cursor.suffix(snapshot), snapshot);
new_flaps new_creases
}; };
new_ids new_ids
} }
pub fn remove( pub fn remove(
&mut self, &mut self,
ids: impl IntoIterator<Item = FlapId>, ids: impl IntoIterator<Item = CreaseId>,
snapshot: &MultiBufferSnapshot, snapshot: &MultiBufferSnapshot,
) { ) {
let mut removals = Vec::new(); let mut removals = Vec::new();
@ -184,24 +186,24 @@ impl FlapMap {
AnchorRangeExt::cmp(a_range, b_range, snapshot).then(b_id.cmp(&a_id)) AnchorRangeExt::cmp(a_range, b_range, snapshot).then(b_id.cmp(&a_id))
}); });
self.snapshot.flaps = { self.snapshot.creases = {
let mut new_flaps = SumTree::new(); let mut new_creases = SumTree::new();
let mut cursor = self.snapshot.flaps.cursor::<ItemSummary>(); let mut cursor = self.snapshot.creases.cursor::<ItemSummary>();
for (id, range) in removals { for (id, range) in removals {
new_flaps.append(cursor.slice(&range, Bias::Left, snapshot), snapshot); new_creases.append(cursor.slice(&range, Bias::Left, snapshot), snapshot);
while let Some(item) = cursor.item() { while let Some(item) = cursor.item() {
cursor.next(snapshot); cursor.next(snapshot);
if item.id == id { if item.id == id {
break; break;
} else { } else {
new_flaps.push(item.clone(), snapshot); new_creases.push(item.clone(), snapshot);
} }
} }
} }
new_flaps.append(cursor.suffix(snapshot), snapshot); new_creases.append(cursor.suffix(snapshot), snapshot);
new_flaps new_creases
}; };
} }
} }
@ -227,17 +229,17 @@ impl sum_tree::Summary for ItemSummary {
} }
} }
impl sum_tree::Item for FlapItem { impl sum_tree::Item for CreaseItem {
type Summary = ItemSummary; type Summary = ItemSummary;
fn summary(&self) -> Self::Summary { fn summary(&self) -> Self::Summary {
ItemSummary { ItemSummary {
range: self.flap.range.clone(), range: self.crease.range.clone(),
} }
} }
} }
/// Implements `SeekTarget` for `Range<Anchor>` to enable seeking within a `SumTree` of `FlapItem`s. /// Implements `SeekTarget` for `Range<Anchor>` to enable seeking within a `SumTree` of `CreaseItem`s.
impl SeekTarget<'_, ItemSummary, ItemSummary> for Range<Anchor> { impl SeekTarget<'_, ItemSummary, ItemSummary> for Range<Anchor> {
fn cmp(&self, cursor_location: &ItemSummary, snapshot: &MultiBufferSnapshot) -> Ordering { fn cmp(&self, cursor_location: &ItemSummary, snapshot: &MultiBufferSnapshot) -> Ordering {
AnchorRangeExt::cmp(self, &cursor_location.range, snapshot) AnchorRangeExt::cmp(self, &cursor_location.range, snapshot)
@ -257,48 +259,48 @@ mod test {
use multi_buffer::MultiBuffer; use multi_buffer::MultiBuffer;
#[gpui::test] #[gpui::test]
fn test_insert_and_remove_flaps(cx: &mut AppContext) { fn test_insert_and_remove_creases(cx: &mut AppContext) {
let text = "line1\nline2\nline3\nline4\nline5"; let text = "line1\nline2\nline3\nline4\nline5";
let buffer = MultiBuffer::build_simple(text, cx); let buffer = MultiBuffer::build_simple(text, cx);
let snapshot = buffer.read_with(cx, |buffer, cx| buffer.snapshot(cx)); let snapshot = buffer.read_with(cx, |buffer, cx| buffer.snapshot(cx));
let mut flap_map = FlapMap::default(); let mut crease_map = CreaseMap::default();
// Insert flaps // Insert creases
let flaps = [ let creases = [
Flap::new( Crease::new(
snapshot.anchor_before(Point::new(1, 0))..snapshot.anchor_after(Point::new(1, 5)), snapshot.anchor_before(Point::new(1, 0))..snapshot.anchor_after(Point::new(1, 5)),
FoldPlaceholder::test(), FoldPlaceholder::test(),
|_row, _folded, _toggle, _cx| div(), |_row, _folded, _toggle, _cx| div(),
|_row, _folded, _cx| div(), |_row, _folded, _cx| div(),
), ),
Flap::new( Crease::new(
snapshot.anchor_before(Point::new(3, 0))..snapshot.anchor_after(Point::new(3, 5)), snapshot.anchor_before(Point::new(3, 0))..snapshot.anchor_after(Point::new(3, 5)),
FoldPlaceholder::test(), FoldPlaceholder::test(),
|_row, _folded, _toggle, _cx| div(), |_row, _folded, _toggle, _cx| div(),
|_row, _folded, _cx| div(), |_row, _folded, _cx| div(),
), ),
]; ];
let flap_ids = flap_map.insert(flaps, &snapshot); let crease_ids = crease_map.insert(creases, &snapshot);
assert_eq!(flap_ids.len(), 2); assert_eq!(crease_ids.len(), 2);
// Verify flaps are inserted // Verify creases are inserted
let flap_snapshot = flap_map.snapshot(); let crease_snapshot = crease_map.snapshot();
assert!(flap_snapshot assert!(crease_snapshot
.query_row(MultiBufferRow(1), &snapshot) .query_row(MultiBufferRow(1), &snapshot)
.is_some()); .is_some());
assert!(flap_snapshot assert!(crease_snapshot
.query_row(MultiBufferRow(3), &snapshot) .query_row(MultiBufferRow(3), &snapshot)
.is_some()); .is_some());
// Remove flaps // Remove creases
flap_map.remove(flap_ids, &snapshot); crease_map.remove(crease_ids, &snapshot);
// Verify flaps are removed // Verify creases are removed
let flap_snapshot = flap_map.snapshot(); let crease_snapshot = crease_map.snapshot();
assert!(flap_snapshot assert!(crease_snapshot
.query_row(MultiBufferRow(1), &snapshot) .query_row(MultiBufferRow(1), &snapshot)
.is_none()); .is_none());
assert!(flap_snapshot assert!(crease_snapshot
.query_row(MultiBufferRow(3), &snapshot) .query_row(MultiBufferRow(3), &snapshot)
.is_none()); .is_none());
} }

View file

@ -9909,22 +9909,22 @@ impl Editor {
} }
} }
pub fn insert_flaps( pub fn insert_creases(
&mut self, &mut self,
flaps: impl IntoIterator<Item = Flap>, creases: impl IntoIterator<Item = Crease>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Vec<FlapId> { ) -> Vec<CreaseId> {
self.display_map self.display_map
.update(cx, |map, cx| map.insert_flaps(flaps, cx)) .update(cx, |map, cx| map.insert_creases(creases, cx))
} }
pub fn remove_flaps( pub fn remove_creases(
&mut self, &mut self,
ids: impl IntoIterator<Item = FlapId>, ids: impl IntoIterator<Item = CreaseId>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) { ) {
self.display_map self.display_map
.update(cx, |map, cx| map.remove_flaps(ids, cx)); .update(cx, |map, cx| map.remove_creases(ids, cx));
} }
pub fn longest_row(&self, cx: &mut AppContext) -> DisplayRow { pub fn longest_row(&self, cx: &mut AppContext) -> DisplayRow {
@ -11759,8 +11759,8 @@ impl EditorSnapshot {
) -> Option<AnyElement> { ) -> Option<AnyElement> {
let folded = self.is_line_folded(buffer_row); let folded = self.is_line_folded(buffer_row);
if let Some(flap) = self if let Some(crease) = self
.flap_snapshot .crease_snapshot
.query_row(buffer_row, &self.buffer_snapshot) .query_row(buffer_row, &self.buffer_snapshot)
{ {
let toggle_callback = Arc::new(move |folded, cx: &mut WindowContext| { let toggle_callback = Arc::new(move |folded, cx: &mut WindowContext| {
@ -11775,7 +11775,7 @@ impl EditorSnapshot {
} }
}); });
Some((flap.render_toggle)( Some((crease.render_toggle)(
buffer_row, buffer_row,
folded, folded,
toggle_callback, toggle_callback,
@ -11801,16 +11801,16 @@ impl EditorSnapshot {
} }
} }
pub fn render_flap_trailer( pub fn render_crease_trailer(
&self, &self,
buffer_row: MultiBufferRow, buffer_row: MultiBufferRow,
cx: &mut WindowContext, cx: &mut WindowContext,
) -> Option<AnyElement> { ) -> Option<AnyElement> {
let folded = self.is_line_folded(buffer_row); let folded = self.is_line_folded(buffer_row);
let flap = self let crease = self
.flap_snapshot .crease_snapshot
.query_row(buffer_row, &self.buffer_snapshot)?; .query_row(buffer_row, &self.buffer_snapshot)?;
Some((flap.render_trailer)(buffer_row, folded, cx)) Some((crease.render_trailer)(buffer_row, folded, cx))
} }
} }

View file

@ -12049,7 +12049,7 @@ async fn test_active_indent_guide_non_matching_indent(cx: &mut gpui::TestAppCont
} }
#[gpui::test] #[gpui::test]
fn test_flap_insertion_and_rendering(cx: &mut TestAppContext) { fn test_crease_insertion_and_rendering(cx: &mut TestAppContext) {
init_test(cx, |_| {}); init_test(cx, |_| {});
let editor = cx.add_window(|cx| { let editor = cx.add_window(|cx| {
@ -12070,7 +12070,7 @@ fn test_flap_insertion_and_rendering(cx: &mut TestAppContext) {
callback: Arc<dyn Fn(bool, &mut WindowContext) + Send + Sync>, callback: Arc<dyn Fn(bool, &mut WindowContext) + Send + Sync>,
} }
let flap = Flap::new( let crease = Crease::new(
range, range,
FoldPlaceholder::test(), FoldPlaceholder::test(),
{ {
@ -12087,7 +12087,7 @@ fn test_flap_insertion_and_rendering(cx: &mut TestAppContext) {
|_row, _folded, _cx| div(), |_row, _folded, _cx| div(),
); );
editor.insert_flaps(Some(flap), cx); editor.insert_creases(Some(crease), cx);
let snapshot = editor.snapshot(cx); let snapshot = editor.snapshot(cx);
let _div = snapshot.render_fold_toggle(MultiBufferRow(1), false, cx.view().clone(), cx); let _div = snapshot.render_fold_toggle(MultiBufferRow(1), false, cx.view().clone(), cx);
snapshot snapshot

View file

@ -1136,7 +1136,7 @@ impl EditorElement {
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn prepaint_flap_trailers( fn prepaint_crease_trailers(
&self, &self,
trailers: Vec<Option<AnyElement>>, trailers: Vec<Option<AnyElement>>,
lines: &[LineWithInvisibles], lines: &[LineWithInvisibles],
@ -1145,7 +1145,7 @@ impl EditorElement {
scroll_pixel_position: gpui::Point<Pixels>, scroll_pixel_position: gpui::Point<Pixels>,
em_width: Pixels, em_width: Pixels,
cx: &mut WindowContext, cx: &mut WindowContext,
) -> Vec<Option<FlapTrailerLayout>> { ) -> Vec<Option<CreaseTrailerLayout>> {
trailers trailers
.into_iter() .into_iter()
.enumerate() .enumerate()
@ -1170,7 +1170,7 @@ impl EditorElement {
let centering_offset = point(px(0.), (line_height - size.height) / 2.); let centering_offset = point(px(0.), (line_height - size.height) / 2.);
let origin = content_origin + position + centering_offset; let origin = content_origin + position + centering_offset;
element.prepaint_as_root(origin, available_space, cx); element.prepaint_as_root(origin, available_space, cx);
Some(FlapTrailerLayout { Some(CreaseTrailerLayout {
element, element,
bounds: Bounds::new(origin, size), bounds: Bounds::new(origin, size),
}) })
@ -1266,7 +1266,7 @@ impl EditorElement {
display_row: DisplayRow, display_row: DisplayRow,
display_snapshot: &DisplaySnapshot, display_snapshot: &DisplaySnapshot,
line_layout: &LineWithInvisibles, line_layout: &LineWithInvisibles,
flap_trailer: Option<&FlapTrailerLayout>, crease_trailer: Option<&CreaseTrailerLayout>,
em_width: Pixels, em_width: Pixels,
content_origin: gpui::Point<Pixels>, content_origin: gpui::Point<Pixels>,
scroll_pixel_position: gpui::Point<Pixels>, scroll_pixel_position: gpui::Point<Pixels>,
@ -1306,8 +1306,8 @@ impl EditorElement {
let start_x = { let start_x = {
const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 6.; const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 6.;
let line_end = if let Some(flap_trailer) = flap_trailer { let line_end = if let Some(crease_trailer) = crease_trailer {
flap_trailer.bounds.right() crease_trailer.bounds.right()
} else { } else {
content_origin.x - scroll_pixel_position.x + line_layout.width content_origin.x - scroll_pixel_position.x + line_layout.width
}; };
@ -1779,7 +1779,7 @@ impl EditorElement {
} }
} }
fn layout_flap_trailers( fn layout_crease_trailers(
&self, &self,
buffer_rows: impl IntoIterator<Item = Option<MultiBufferRow>>, buffer_rows: impl IntoIterator<Item = Option<MultiBufferRow>>,
snapshot: &EditorSnapshot, snapshot: &EditorSnapshot,
@ -1789,7 +1789,7 @@ impl EditorElement {
.into_iter() .into_iter()
.map(|row| { .map(|row| {
if let Some(multibuffer_row) = row { if let Some(multibuffer_row) = row {
snapshot.render_flap_trailer(multibuffer_row, cx) snapshot.render_crease_trailer(multibuffer_row, cx)
} else { } else {
None None
} }
@ -3067,8 +3067,8 @@ impl EditorElement {
self.paint_redactions(layout, cx); self.paint_redactions(layout, cx);
self.paint_cursors(layout, cx); self.paint_cursors(layout, cx);
self.paint_inline_blame(layout, cx); self.paint_inline_blame(layout, cx);
cx.with_element_namespace("flap_trailers", |cx| { cx.with_element_namespace("crease_trailers", |cx| {
for trailer in layout.flap_trailers.iter_mut().flatten() { for trailer in layout.crease_trailers.iter_mut().flatten() {
trailer.element.paint(cx); trailer.element.paint(cx);
} }
}); });
@ -4697,8 +4697,8 @@ impl Element for EditorElement {
cx, cx,
) )
}); });
let flap_trailers = cx.with_element_namespace("flap_trailers", |cx| { let crease_trailers = cx.with_element_namespace("crease_trailers", |cx| {
self.layout_flap_trailers(buffer_rows.iter().copied(), &snapshot, cx) self.layout_crease_trailers(buffer_rows.iter().copied(), &snapshot, cx)
}); });
let display_hunks = self.layout_git_gutters( let display_hunks = self.layout_git_gutters(
@ -4759,9 +4759,9 @@ impl Element for EditorElement {
cx, cx,
); );
let flap_trailers = cx.with_element_namespace("flap_trailers", |cx| { let crease_trailers = cx.with_element_namespace("crease_trailers", |cx| {
self.prepaint_flap_trailers( self.prepaint_crease_trailers(
flap_trailers, crease_trailers,
&line_layouts, &line_layouts,
line_height, line_height,
content_origin, content_origin,
@ -4777,12 +4777,12 @@ impl Element for EditorElement {
if (start_row..end_row).contains(&display_row) { if (start_row..end_row).contains(&display_row) {
let line_ix = display_row.minus(start_row) as usize; let line_ix = display_row.minus(start_row) as usize;
let line_layout = &line_layouts[line_ix]; let line_layout = &line_layouts[line_ix];
let flap_trailer_layout = flap_trailers[line_ix].as_ref(); let crease_trailer_layout = crease_trailers[line_ix].as_ref();
inline_blame = self.layout_inline_blame( inline_blame = self.layout_inline_blame(
display_row, display_row,
&snapshot.display_snapshot, &snapshot.display_snapshot,
line_layout, line_layout,
flap_trailer_layout, crease_trailer_layout,
em_width, em_width,
content_origin, content_origin,
scroll_pixel_position, scroll_pixel_position,
@ -5037,7 +5037,7 @@ impl Element for EditorElement {
test_indicators, test_indicators,
code_actions_indicator, code_actions_indicator,
gutter_fold_toggles, gutter_fold_toggles,
flap_trailers, crease_trailers,
tab_invisible, tab_invisible,
space_invisible, space_invisible,
} }
@ -5168,7 +5168,7 @@ pub struct EditorLayout {
code_actions_indicator: Option<AnyElement>, code_actions_indicator: Option<AnyElement>,
test_indicators: Vec<AnyElement>, test_indicators: Vec<AnyElement>,
gutter_fold_toggles: Vec<Option<AnyElement>>, gutter_fold_toggles: Vec<Option<AnyElement>>,
flap_trailers: Vec<Option<FlapTrailerLayout>>, crease_trailers: Vec<Option<CreaseTrailerLayout>>,
mouse_context_menu: Option<AnyElement>, mouse_context_menu: Option<AnyElement>,
tab_invisible: ShapedLine, tab_invisible: ShapedLine,
space_invisible: ShapedLine, space_invisible: ShapedLine,
@ -5292,7 +5292,7 @@ impl ScrollbarLayout {
} }
} }
struct FlapTrailerLayout { struct CreaseTrailerLayout {
element: AnyElement, element: AnyElement,
bounds: Bounds<Pixels>, bounds: Bounds<Pixels>,
} }