Introduce "Near" block type (#28032)

A "Near" block acts similarly to a "Below" block, but can (if it's
height is <= one line height) be shown on the end of the preceding line
instead of adding an entire blank line to the editor.

You can test it out by pasting this into `go_to_diagnostic_impl` and
then press `F8`
```
        let buffer = self.buffer.read(cx).snapshot(cx);
        let selection = self.selections.newest_anchor();

        self.display_map.update(cx, |display_map, cx| {
            display_map.insert_blocks(
                [BlockProperties {
                    placement: BlockPlacement::Near(selection.start),
                    height: Some(1),
                    style: BlockStyle::Flex,
                    render: Arc::new(|_| {
                        div()
                            .w(px(100.))
                            .h(px(16.))
                            .bg(gpui::hsla(0., 0., 1., 0.5))
                            .into_any_element()
                    }),
                    priority: 0,
                }],
                cx,
            )
        });
        return;
```

Release Notes:

- N/A

---------

Co-authored-by: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Conrad Irwin 2025-04-04 17:37:42 -06:00 committed by GitHub
parent 10821aae2c
commit d0e82b0538
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 246 additions and 191 deletions

View file

@ -8717,7 +8717,7 @@ impl Editor {
let blocks = vec![BlockProperties {
style: BlockStyle::Sticky,
placement: BlockPlacement::Above(anchor),
height,
height: Some(height),
render: Arc::new(move |cx| {
*cloned_prompt.read(cx).gutter_dimensions.lock() = *cx.gutter_dimensions;
cloned_prompt.clone().into_any_element()
@ -12801,7 +12801,6 @@ impl Editor {
) {
let buffer = self.buffer.read(cx).snapshot(cx);
let selection = self.selections.newest::<usize>(cx);
// If there is an active Diagnostic Popover jump to its diagnostic instead.
if direction == Direction::Next {
if let Some(popover) = self.hover_state.diagnostic_popover.as_ref() {
@ -13806,7 +13805,7 @@ impl Editor {
[BlockProperties {
style: BlockStyle::Flex,
placement: BlockPlacement::Below(range.start),
height: 1,
height: Some(1),
render: Arc::new({
let rename_editor = rename_editor.clone();
move |cx: &mut BlockContext| {
@ -14273,7 +14272,7 @@ impl Editor {
placement: BlockPlacement::Below(
buffer.anchor_after(entry.range.start),
),
height: message_height,
height: Some(message_height),
render: diagnostic_block_renderer(diagnostic, None, true),
priority: 0,
}