Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions crates/editor/src/display_map/block_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,16 @@ impl<P: Debug> Debug for BlockProperties<P> {
pub enum BlockStyle {
Fixed,
Flex,
/// Like `Flex` but doesn't use the gutter
FlexClipped,
Sticky,
}

#[derive(Debug, Default, Copy, Clone)]
pub struct EditorMargins {
pub gutter: GutterDimensions,
pub right: Pixels,
pub extended_right: Pixels,
}

#[derive(gpui::AppContext, gpui::VisualContext)]
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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,
Expand Down
32 changes: 26 additions & 6 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4224,7 +4224,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!(),
};
Expand Down Expand Up @@ -4267,7 +4275,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(),
});
}
Expand All @@ -4281,12 +4289,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),
};
Expand Down Expand Up @@ -4346,6 +4359,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>,
Expand All @@ -4367,6 +4381,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);
}
Expand Down Expand Up @@ -9561,11 +9579,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| {
Expand Down Expand Up @@ -10449,6 +10468,7 @@ impl Element for EditorElement {
self.layout_blocks(
&mut blocks,
&hitbox,
&gutter_hitbox,
line_height,
scroll_position,
scroll_pixel_position,
Expand Down