Merge branch 'main' into edit-prediction-syntax-highlighting

This commit is contained in:
Agus Zubiaga 2025-01-22 11:08:41 -03:00
commit 3e34c2293d
4 changed files with 37 additions and 54 deletions

View file

@ -1757,7 +1757,6 @@ impl<'a> BlockChunks<'a> {
pub struct StickyHeaderExcerpt<'a> {
pub excerpt: &'a ExcerptInfo,
pub next_excerpt_controls_present: bool,
// TODO az remove option
pub next_buffer_row: Option<u32>,
}

View file

@ -486,6 +486,7 @@ enum InlineCompletion {
Edit {
edits: Vec<(Range<Anchor>, String)>,
edit_preview: Option<EditPreview>,
single_line: bool,
},
Move(Anchor),
}
@ -4883,16 +4884,12 @@ impl Editor {
}
let first_edit_start = edits.first().unwrap().0.start;
let edit_start_row = first_edit_start
.to_point(&multibuffer)
.row
.saturating_sub(2);
let first_edit_start_point = first_edit_start.to_point(&multibuffer);
let edit_start_row = first_edit_start_point.row.saturating_sub(2);
let last_edit_end = edits.last().unwrap().0.end;
let edit_end_row = cmp::min(
multibuffer.max_point().row,
last_edit_end.to_point(&multibuffer).row + 2,
);
let last_edit_end_point = last_edit_end.to_point(&multibuffer);
let edit_end_row = cmp::min(multibuffer.max_point().row, last_edit_end_point.row + 2);
let cursor_row = cursor.to_point(&multibuffer).row;
@ -4935,8 +4932,13 @@ impl Editor {
}
invalidation_row_range = edit_start_row..edit_end_row;
let single_line = first_edit_start_point.row == last_edit_end_point.row
&& !edits.iter().any(|(_, edit)| edit.contains('\n'));
completion = InlineCompletion::Edit {
edits,
single_line,
edit_preview: inline_completion.edit_preview,
};
};
@ -4982,6 +4984,7 @@ impl Editor {
InlineCompletion::Edit {
edits,
edit_preview,
single_line: _,
} => edit_preview
.as_ref()
.and_then(|edit_preview| {

View file

@ -1592,7 +1592,6 @@ impl EditorElement {
&self,
display_row: DisplayRow,
display_snapshot: &DisplaySnapshot,
buffer_snapshot: &MultiBufferSnapshot,
line_layout: &LineWithInvisibles,
crease_trailer: Option<&CreaseTrailerLayout>,
em_width: Pixels,
@ -1629,11 +1628,8 @@ impl EditorElement {
if let Some(inline_completion) = editor.active_inline_completion.as_ref() {
match &inline_completion.completion {
InlineCompletion::Edit {
edits,
edit_preview: _,
} if single_line_edit(&edits, buffer_snapshot).is_some() => {
padding += INLINE_ACCEPT_SUGGESTION_EM_WIDTHS
}
single_line: true, ..
} => padding += INLINE_ACCEPT_SUGGESTION_EM_WIDTHS,
_ => {}
}
}
@ -3393,6 +3389,7 @@ impl EditorElement {
InlineCompletion::Edit {
edits,
edit_preview,
single_line,
} => {
if self.editor.read(cx).has_active_completions_menu() {
return None;
@ -3417,28 +3414,30 @@ impl EditorElement {
return None;
}
if let Some(range) = single_line_edit(&edits, &editor_snapshot.buffer_snapshot) {
let mut element = inline_completion_tab_indicator("Accept", None, cx);
let target_display_point = range.end.to_display_point(editor_snapshot);
let target_line_end = DisplayPoint::new(
target_display_point.row(),
editor_snapshot.line_len(target_display_point.row()),
);
let origin = self.editor.update(cx, |editor, cx| {
editor.display_to_pixel_point(target_line_end, editor_snapshot, cx)
})?;
element.prepaint_as_root(
text_bounds.origin + origin + point(PADDING_X, px(0.)),
AvailableSpace::min_size(),
cx,
);
return Some(element);
}
if all_edits_insertions_or_deletions(edits, &editor_snapshot.buffer_snapshot) {
if *single_line {
let range = &edits.first()?.0;
let target_display_point = range.end.to_display_point(editor_snapshot);
let target_line_end = DisplayPoint::new(
target_display_point.row(),
editor_snapshot.line_len(target_display_point.row()),
);
let origin = self.editor.update(cx, |editor, cx| {
editor.display_to_pixel_point(target_line_end, editor_snapshot, cx)
})?;
let mut element = inline_completion_tab_indicator("Accept", None, cx);
element.prepaint_as_root(
text_bounds.origin + origin + point(PADDING_X, px(0.)),
AvailableSpace::min_size(),
cx,
);
return Some(element);
}
return None;
}
@ -5251,22 +5250,6 @@ fn inline_completion_tab_indicator(
.into_any()
}
fn single_line_edit<'a>(
edits: &'a [(Range<Anchor>, String)],
snapshot: &MultiBufferSnapshot,
) -> Option<&'a Range<Anchor>> {
let [(range, _)] = edits else {
return None;
};
let point_range = range.to_point(&snapshot);
if point_range.start.row == point_range.end.row {
Some(range)
} else {
None
}
}
fn all_edits_insertions_or_deletions(
edits: &Vec<(Range<Anchor>, String)>,
snapshot: &MultiBufferSnapshot,
@ -6551,7 +6534,6 @@ impl Element for EditorElement {
inline_blame = self.layout_inline_blame(
display_row,
&snapshot.display_snapshot,
&snapshot.buffer_snapshot,
line_layout,
crease_trailer_layout,
em_width,

View file

@ -1211,7 +1211,6 @@ impl Element for Div {
state.child_bounds = Vec::with_capacity(request_layout.child_layout_ids.len());
state.bounds = bounds;
let requested = state.requested_scroll_top.take();
// TODO az
for (ix, child_layout_id) in request_layout.child_layout_ids.iter().enumerate() {
let child_bounds = cx.layout_bounds(*child_layout_id);