Skip to content

Commit

Permalink
Fix accepting partial inline completion (cherry-pick #23312) (#23327)
Browse files Browse the repository at this point in the history
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 <me@as-cii.com>
  • Loading branch information
gcp-cherry-pick-bot[bot] and as-cii authored Jan 20, 2025
1 parent ce3752d commit fba2828
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4720,8 +4720,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::<usize>(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()
Expand All @@ -4744,6 +4755,8 @@ impl Editor {

self.refresh_inline_completion(true, true, cx);
cx.notify();
} else {
self.accept_inline_completion(&Default::default(), cx);
}
}
}
Expand Down

0 comments on commit fba2828

Please sign in to comment.