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:
parent
10821aae2c
commit
d0e82b0538
12 changed files with 246 additions and 191 deletions
|
@ -535,7 +535,7 @@ impl ProjectDiagnosticsEditor {
|
|||
group_state.block_count += 1;
|
||||
blocks_to_add.push(BlockProperties {
|
||||
placement: BlockPlacement::Above(header_position),
|
||||
height: 2,
|
||||
height: Some(2),
|
||||
style: BlockStyle::Sticky,
|
||||
render: diagnostic_header_renderer(primary),
|
||||
priority: 0,
|
||||
|
@ -557,7 +557,9 @@ impl ProjectDiagnosticsEditor {
|
|||
excerpt_id,
|
||||
entry.range.start,
|
||||
)),
|
||||
height: diagnostic.message.matches('\n').count() as u32 + 1,
|
||||
height: Some(
|
||||
diagnostic.message.matches('\n').count() as u32 + 1,
|
||||
),
|
||||
style: BlockStyle::Fixed,
|
||||
render: diagnostic_block_renderer(diagnostic, None, true),
|
||||
priority: 0,
|
||||
|
@ -613,9 +615,9 @@ impl ProjectDiagnosticsEditor {
|
|||
excerpts_snapshot.anchor_in_excerpt(excerpt_id, text_anchor)?,
|
||||
)
|
||||
}
|
||||
BlockPlacement::Replace(_) => {
|
||||
BlockPlacement::Replace(_) | BlockPlacement::Near(_) => {
|
||||
unreachable!(
|
||||
"no Replace block should have been pushed to blocks_to_add"
|
||||
"no Near/Replace block should have been pushed to blocks_to_add"
|
||||
)
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue