Avoid losing focus when block decorations go offscreen (#14815)
Release Notes: - Fixed a bug that caused focus to be lost when renames and inline assists were scrolled offscreen. --------- Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
f5d50f2b1e
commit
d61eaea4b9
18 changed files with 941 additions and 584 deletions
|
@ -10,7 +10,7 @@ use anyhow::Result;
|
|||
use collections::{BTreeSet, HashSet};
|
||||
use editor::{
|
||||
diagnostic_block_renderer,
|
||||
display_map::{BlockDisposition, BlockId, BlockProperties, BlockStyle, RenderBlock},
|
||||
display_map::{BlockDisposition, BlockProperties, BlockStyle, CustomBlockId, RenderBlock},
|
||||
highlight_diagnostic_message,
|
||||
scroll::Autoscroll,
|
||||
Editor, EditorEvent, ExcerptId, ExcerptRange, MultiBuffer, ToOffset,
|
||||
|
@ -85,7 +85,7 @@ struct DiagnosticGroupState {
|
|||
primary_diagnostic: DiagnosticEntry<language::Anchor>,
|
||||
primary_excerpt_ix: usize,
|
||||
excerpts: Vec<ExcerptId>,
|
||||
blocks: HashSet<BlockId>,
|
||||
blocks: HashSet<CustomBlockId>,
|
||||
block_count: usize,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::*;
|
||||
use collections::HashMap;
|
||||
use editor::{
|
||||
display_map::{BlockContext, DisplayRow, TransformBlock},
|
||||
display_map::{Block, BlockContext, DisplayRow},
|
||||
DisplayPoint, GutterDimensions,
|
||||
};
|
||||
use gpui::{px, AvailableSpace, Stateful, TestAppContext, VisualTestContext};
|
||||
|
@ -974,9 +974,9 @@ fn editor_blocks(
|
|||
snapshot
|
||||
.blocks_in_range(DisplayRow(0)..snapshot.max_point().row())
|
||||
.filter_map(|(row, block)| {
|
||||
let transform_block_id = block.id();
|
||||
let block_id = block.id();
|
||||
let name: SharedString = match block {
|
||||
TransformBlock::Custom(block) => {
|
||||
Block::Custom(block) => {
|
||||
let mut element = block.render(&mut BlockContext {
|
||||
context: cx,
|
||||
anchor_x: px(0.),
|
||||
|
@ -984,7 +984,7 @@ fn editor_blocks(
|
|||
line_height: px(0.),
|
||||
em_width: px(0.),
|
||||
max_width: px(0.),
|
||||
transform_block_id,
|
||||
block_id,
|
||||
editor_style: &editor::EditorStyle::default(),
|
||||
});
|
||||
let element = element.downcast_mut::<Stateful<Div>>().unwrap();
|
||||
|
@ -996,7 +996,7 @@ fn editor_blocks(
|
|||
.ok()?
|
||||
}
|
||||
|
||||
TransformBlock::ExcerptHeader {
|
||||
Block::ExcerptHeader {
|
||||
starts_new_buffer, ..
|
||||
} => {
|
||||
if *starts_new_buffer {
|
||||
|
@ -1005,7 +1005,7 @@ fn editor_blocks(
|
|||
EXCERPT_HEADER.into()
|
||||
}
|
||||
}
|
||||
TransformBlock::ExcerptFooter { .. } => EXCERPT_FOOTER.into(),
|
||||
Block::ExcerptFooter { .. } => EXCERPT_FOOTER.into(),
|
||||
};
|
||||
|
||||
Some((row, name))
|
||||
|
|
|
@ -3,8 +3,8 @@ use collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
|||
use editor::{
|
||||
diagnostic_block_renderer,
|
||||
display_map::{
|
||||
BlockContext, BlockDisposition, BlockId, BlockProperties, BlockStyle, RenderBlock,
|
||||
TransformBlockId,
|
||||
BlockContext, BlockDisposition, BlockId, BlockProperties, BlockStyle, CustomBlockId,
|
||||
RenderBlock,
|
||||
},
|
||||
scroll::Autoscroll,
|
||||
Bias, Editor, EditorEvent, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot, ToPoint,
|
||||
|
@ -71,7 +71,7 @@ struct PathState {
|
|||
path: ProjectPath,
|
||||
first_excerpt_id: Option<ExcerptId>,
|
||||
last_excerpt_id: Option<ExcerptId>,
|
||||
diagnostics: Vec<(DiagnosticData, BlockId)>,
|
||||
diagnostics: Vec<(DiagnosticData, CustomBlockId)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -657,10 +657,10 @@ fn compare_diagnostic_range_edges(
|
|||
struct PathUpdate {
|
||||
path_excerpts_borders: (Option<ExcerptId>, Option<ExcerptId>),
|
||||
latest_excerpt_id: ExcerptId,
|
||||
new_diagnostics: Vec<(DiagnosticData, Option<BlockId>)>,
|
||||
new_diagnostics: Vec<(DiagnosticData, Option<CustomBlockId>)>,
|
||||
diagnostics_by_row_label: BTreeMap<MultiBufferRow, (editor::Anchor, Vec<usize>)>,
|
||||
blocks_to_remove: HashSet<BlockId>,
|
||||
unchanged_blocks: HashMap<usize, BlockId>,
|
||||
blocks_to_remove: HashSet<CustomBlockId>,
|
||||
unchanged_blocks: HashMap<usize, CustomBlockId>,
|
||||
excerpts_with_new_diagnostics: HashSet<ExcerptId>,
|
||||
excerpts_to_remove: Vec<ExcerptId>,
|
||||
excerpt_expands: HashMap<(ExpandExcerptDirection, u32), Vec<ExcerptId>>,
|
||||
|
@ -749,7 +749,7 @@ impl PathUpdate {
|
|||
context: u32,
|
||||
multi_buffer_snapshot: MultiBufferSnapshot,
|
||||
buffer_snapshot: BufferSnapshot,
|
||||
current_diagnostics: impl Iterator<Item = &'a (DiagnosticData, BlockId)> + 'a,
|
||||
current_diagnostics: impl Iterator<Item = &'a (DiagnosticData, CustomBlockId)> + 'a,
|
||||
) {
|
||||
let mut current_diagnostics = current_diagnostics.fuse().peekable();
|
||||
let mut excerpts_to_expand =
|
||||
|
@ -1234,7 +1234,10 @@ impl PathUpdate {
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn new_blocks(mut self, new_block_ids: Vec<BlockId>) -> Vec<(DiagnosticData, BlockId)> {
|
||||
fn new_blocks(
|
||||
mut self,
|
||||
new_block_ids: Vec<CustomBlockId>,
|
||||
) -> Vec<(DiagnosticData, CustomBlockId)> {
|
||||
let mut new_block_ids = new_block_ids.into_iter().fuse();
|
||||
for (_, (_, grouped_diagnostics)) in self.diagnostics_by_row_label {
|
||||
let mut created_block_id = None;
|
||||
|
@ -1285,8 +1288,8 @@ fn render_same_line_diagnostics(
|
|||
folded_block_height: u8,
|
||||
) -> RenderBlock {
|
||||
Box::new(move |cx: &mut BlockContext| {
|
||||
let block_id = match cx.transform_block_id {
|
||||
TransformBlockId::Block(block_id) => block_id,
|
||||
let block_id = match cx.block_id {
|
||||
BlockId::Custom(block_id) => block_id,
|
||||
_ => {
|
||||
debug_panic!("Expected a block id for the diagnostics block");
|
||||
return div().into_any_element();
|
||||
|
@ -1320,7 +1323,7 @@ fn render_same_line_diagnostics(
|
|||
.child(v_flex().size_full().when_some_else(
|
||||
toggle_expand_label,
|
||||
|parent, label| {
|
||||
parent.child(Button::new(cx.transform_block_id, label).on_click({
|
||||
parent.child(Button::new(cx.block_id, label).on_click({
|
||||
let diagnostics = Arc::clone(&diagnostics);
|
||||
move |_, cx| {
|
||||
let new_expanded = !expanded;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue