Fix rendering of focused offscreen block when scrolled to bottom (#15449)

This change fixes a bug when a block is focused but offscreen.
Previously, we used the last row, but this caused a spurious block to be
rendered when scrolled to the end of the file. With this change we
always render off-screen blocks below the editor's clipping box.

Release Notes:

- Fixed a bug that caused the inline assistant to be displayed twice in
certain circumstances.

Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2024-07-29 20:39:21 +02:00 committed by GitHub
parent 085d41b121
commit 02c51c9b56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2415,7 +2415,7 @@ impl EditorElement {
fixed_block_max_width = fixed_block_max_width.max(element_size.width + em_width); fixed_block_max_width = fixed_block_max_width.max(element_size.width + em_width);
blocks.push(BlockLayout { blocks.push(BlockLayout {
id: block_id, id: block_id,
row, row: Some(row),
element, element,
available_space, available_space,
style: BlockStyle::Fixed, style: BlockStyle::Fixed,
@ -2460,7 +2460,7 @@ impl EditorElement {
); );
blocks.push(BlockLayout { blocks.push(BlockLayout {
id: block_id, id: block_id,
row, row: Some(row),
element, element,
available_space, available_space,
style, style,
@ -2507,7 +2507,7 @@ impl EditorElement {
blocks.push(BlockLayout { blocks.push(BlockLayout {
id: block.id(), id: block.id(),
row: rows.end, row: None,
element, element,
available_space, available_space,
style, style,
@ -2530,11 +2530,17 @@ impl EditorElement {
cx: &mut WindowContext, cx: &mut WindowContext,
) { ) {
for block in blocks { for block in blocks {
let mut origin = hitbox.origin let mut origin = if let Some(row) = block.row {
+ point( hitbox.origin
Pixels::ZERO, + point(
block.row.as_f32() * line_height - scroll_pixel_position.y, Pixels::ZERO,
); row.as_f32() * line_height - scroll_pixel_position.y,
)
} else {
// Position the block outside the visible area
hitbox.origin + point(Pixels::ZERO, hitbox.size.height)
};
if !matches!(block.style, BlockStyle::Sticky) { if !matches!(block.style, BlockStyle::Sticky) {
origin += point(-scroll_pixel_position.x, Pixels::ZERO); origin += point(-scroll_pixel_position.x, Pixels::ZERO);
} }
@ -5868,7 +5874,7 @@ impl PositionMap {
struct BlockLayout { struct BlockLayout {
id: BlockId, id: BlockId,
row: DisplayRow, row: Option<DisplayRow>,
element: AnyElement, element: AnyElement,
available_space: Size<AvailableSpace>, available_space: Size<AvailableSpace>,
style: BlockStyle, style: BlockStyle,