Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Add `FlexClipped` block style and use it for spacer blocks (#49478)
Cole Millera1af11c8c3f9
diff --git a/crates/editor/src/display_map/block_map.rs b/crates/editor/src/display_map/block_map.rsindex 85dbcd22e92..daf951eb8fc 100644--- a/crates/editor/src/display_map/block_map.rs+++ b/crates/editor/src/display_map/block_map.rs@@ -265,6 +265,8 @@ impl<P: Debug> Debug for BlockProperties<P> {pub enum BlockStyle {Fixed,Flex,+ /// Like `Flex` but doesn't use the gutter+ FlexClipped,Sticky,}@@ -272,6 +274,7 @@ pub enum BlockStyle {pub struct EditorMargins {pub gutter: GutterDimensions,pub right: Pixels,+ pub extended_right: Pixels,}#[derive(gpui::AppContext, gpui::VisualContext)]@@ -393,8 +396,8 @@ impl Block {Block::Custom(block) => block.style,Block::ExcerptBoundary { .. }| Block::FoldedBuffer { .. }- | Block::BufferHeader { .. }- | Block::Spacer { .. } => BlockStyle::Sticky,+ | Block::BufferHeader { .. } => BlockStyle::Sticky,+ Block::Spacer { .. } => BlockStyle::FlexClipped,}}@@ -1707,7 +1710,7 @@ pub(crate) fn balancing_block(Some(BlockProperties {placement: their_placement,height: my_block.height,- style: BlockStyle::Sticky,+ style: BlockStyle::FlexClipped,render: Arc::new(move |cx| {crate::EditorElement::render_spacer_block(cx.block_id,diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 3ae4713ee4c..520af175974 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -4226,7 +4226,15 @@ impl EditorElement {.size.width.max(fixed_block_max_width)- .max(editor_margins.gutter.width + *scroll_width)+ .max(+ editor_margins.gutter.width + *scroll_width + editor_margins.extended_right,+ )+ .into(),+ (BlockStyle::FlexClipped, _) => hitbox+ .size+ .width+ .max(fixed_block_max_width)+ .max(*scroll_width + editor_margins.extended_right).into(),(BlockStyle::Fixed, _) => unreachable!(),};@@ -4269,7 +4277,7 @@ impl EditorElement {element,available_space: size(width, element_size.height.into()),style,- overlaps_gutter: !block.place_near(),+ overlaps_gutter: !block.place_near() && style != BlockStyle::FlexClipped,is_buffer_header: block.is_buffer_header(),});}@@ -4283,12 +4291,17 @@ impl EditorElement {let style = block.style();let width = match style {BlockStyle::Fixed => AvailableSpace::MinContent,- BlockStyle::Flex => AvailableSpace::Definite(+ BlockStyle::Flex => {+ AvailableSpace::Definite(hitbox.size.width.max(fixed_block_max_width).max(+ editor_margins.gutter.width + *scroll_width + editor_margins.extended_right,+ ))+ }+ BlockStyle::FlexClipped => AvailableSpace::Definite(hitbox.size.width.max(fixed_block_max_width)- .max(editor_margins.gutter.width + *scroll_width),+ .max(*scroll_width + editor_margins.extended_right),),BlockStyle::Sticky => AvailableSpace::Definite(hitbox.size.width),};@@ -4348,6 +4361,7 @@ impl EditorElement {&self,blocks: &mut Vec<BlockLayout>,hitbox: &Hitbox,+ gutter_hitbox: &Hitbox,line_height: Pixels,scroll_position: gpui::Point<ScrollOffset>,scroll_pixel_position: gpui::Point<ScrollPixelOffset>,@@ -4369,6 +4383,10 @@ impl EditorElement {hitbox.origin + point(Pixels::ZERO, hitbox.size.height)};+ if block.style == BlockStyle::FlexClipped {+ origin += point(gutter_hitbox.size.width, Pixels::ZERO);+ }+if !matches!(block.style, BlockStyle::Sticky) {origin += point(Pixels::from(-scroll_pixel_position.x), Pixels::ZERO);}@@ -9581,11 +9599,12 @@ impl Element for EditorElement {let right_margin = minimap_width + vertical_scrollbar_width;- let editor_width =- text_width - gutter_dimensions.margin - 2 * em_width - right_margin;+ let extended_right = 2 * em_width + right_margin;+ let editor_width = text_width - gutter_dimensions.margin - extended_right;let editor_margins = EditorMargins {gutter: gutter_dimensions,right: right_margin,+ extended_right,};snapshot = self.editor.update(cx, |editor, cx| {@@ -10469,6 +10488,7 @@ impl Element for EditorElement {self.layout_blocks(&mut blocks,&hitbox,+ &gutter_hitbox,line_height,scroll_position,scroll_pixel_position,