Separate actions for accepting the inline suggestions and completions (#12094)

Release Notes:
- Added `editor::AcceptInlineCompletion` action (bound to Tab by
default) for accepting inline completions. ([6788](https://github.com/zed-industries/zed/issues/6788))

---------

Signed-off-by: Raphael Lüthy <raphael.luethy@fhnw.ch>
Co-authored-by: Conrad Irvin <conrad@zed.dev>
This commit is contained in:
Raphael Lüthy
2024-05-22 13:51:21 +03:00
committed by GitHub
co-authored by Conrad Irvin
parent 7c9c80d663
commit e68ef944d9
6 changed files with 36 additions and 30 deletions
+18 -26
View File
@@ -4450,23 +4450,25 @@ impl Editor {
}
}
fn accept_inline_completion(&mut self, cx: &mut ViewContext<Self>) -> bool {
if let Some(completion) = self.take_active_inline_completion(cx) {
if let Some(provider) = self.inline_completion_provider() {
provider.accept(cx);
}
cx.emit(EditorEvent::InputHandled {
utf16_range_to_replace: None,
text: completion.text.to_string().into(),
});
self.insert_with_autoindent_mode(&completion.text.to_string(), None, cx);
self.refresh_inline_completion(true, cx);
cx.notify();
true
} else {
false
pub fn accept_inline_completion(
&mut self,
_: &AcceptInlineCompletion,
cx: &mut ViewContext<Self>,
) {
let Some(completion) = self.take_active_inline_completion(cx) else {
return;
};
if let Some(provider) = self.inline_completion_provider() {
provider.accept(cx);
}
cx.emit(EditorEvent::InputHandled {
utf16_range_to_replace: None,
text: completion.text.to_string().into(),
});
self.insert_with_autoindent_mode(&completion.text.to_string(), None, cx);
self.refresh_inline_completion(true, cx);
cx.notify();
}
pub fn accept_partial_inline_completion(
@@ -4966,16 +4968,6 @@ impl Editor {
}
}
// Accept copilot completion if there is only one selection and the cursor is not
// in the leading whitespace.
if self.selections.count() == 1
&& cursor.column >= current_indent.len
&& self.has_active_inline_completion(cx)
{
self.accept_inline_completion(cx);
return;
}
// Otherwise, insert a hard or soft tab.
let settings = buffer.settings_at(cursor, cx);
let tab_size = if settings.hard_tabs {