Fix single line edit prediction detection (#23456)

#23411 introduced an "Accept" callout for single line edits, but the
logic to detect them was incorrect causing it to trigger for multiline
insertions, this PR fixes that.

Release Notes:

- N/A
This commit is contained in:
Agus Zubiaga 2025-01-22 10:00:43 -03:00 committed by GitHub
parent f0b5b0b4df
commit 55721c65d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 35 additions and 43 deletions

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,
@ -1628,11 +1627,9 @@ impl EditorElement {
if let Some(inline_completion) = editor.active_inline_completion.as_ref() {
match &inline_completion.completion {
InlineCompletion::Edit(edits)
if single_line_edit(&edits, buffer_snapshot).is_some() =>
{
padding += INLINE_ACCEPT_SUGGESTION_EM_WIDTHS
}
InlineCompletion::Edit {
single_line: true, ..
} => padding += INLINE_ACCEPT_SUGGESTION_EM_WIDTHS,
_ => {}
}
}
@ -3389,7 +3386,7 @@ impl EditorElement {
Some(element)
}
}
InlineCompletion::Edit(edits) => {
InlineCompletion::Edit { edits, single_line } => {
if self.editor.read(cx).has_active_completions_menu() {
return None;
}
@ -3413,7 +3410,7 @@ impl EditorElement {
return None;
}
if let Some(range) = single_line_edit(&edits, &editor_snapshot.buffer_snapshot) {
if let (true, Some((range, _))) = (single_line, edits.first()) {
let mut element = inline_completion_tab_indicator("Accept", None, cx);
let target_display_point = range.end.to_display_point(editor_snapshot);
@ -5250,22 +5247,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,
@ -6550,7 +6531,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,