From 349fb5254d38380ef688d8f7fd4677429d391186 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 09:40:24 +0100 Subject: [PATCH] Fix accepting partial inline completion (cherry-pick #23312) (#23328) Cherry-picked Fix accepting partial inline completion (#23312) Release Notes: - Fixed a bug that could prevent accepting a partial inline completion. Co-authored-by: Antonio Scandurra --- crates/editor/src/editor.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 7a9a9cbe977bb42572f081c9616081416dbf03dc..0f7a02de484f3c690508e1de55b96a05f23746b3 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4715,8 +4715,19 @@ impl Editor { }); } InlineCompletion::Edit(edits) => { - if edits.len() == 1 && edits[0].0.start == edits[0].0.end { - let text = edits[0].1.as_str(); + // Find an insertion that starts at the cursor position. + let snapshot = self.buffer.read(cx).snapshot(cx); + let cursor_offset = self.selections.newest::(cx).head(); + let insertion = edits.iter().find_map(|(range, text)| { + let range = range.to_offset(&snapshot); + if range.is_empty() && range.start == cursor_offset { + Some(text) + } else { + None + } + }); + + if let Some(text) = insertion { let mut partial_completion = text .chars() .by_ref() @@ -4739,6 +4750,8 @@ impl Editor { self.refresh_inline_completion(true, true, cx); cx.notify(); + } else { + self.accept_inline_completion(&Default::default(), cx); } } }