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:
parent
7c9c80d663
commit
e68ef944d9
6 changed files with 36 additions and 30 deletions
|
@ -501,6 +501,12 @@
|
||||||
"tab": "editor::ConfirmCompletion"
|
"tab": "editor::ConfirmCompletion"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"context": "Editor && inline_completion && !showing_completions",
|
||||||
|
"bindings": {
|
||||||
|
"tab": "editor::AcceptInlineCompletion"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"context": "Editor && showing_code_actions",
|
"context": "Editor && showing_code_actions",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
|
|
|
@ -515,6 +515,12 @@
|
||||||
"tab": "editor::ConfirmCompletion"
|
"tab": "editor::ConfirmCompletion"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"context": "Editor && inline_completion && !showing_completions",
|
||||||
|
"bindings": {
|
||||||
|
"tab": "editor::AcceptInlineCompletion"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"context": "Editor && showing_code_actions",
|
"context": "Editor && showing_code_actions",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
|
|
|
@ -492,8 +492,8 @@ mod tests {
|
||||||
assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");
|
assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");
|
||||||
assert_eq!(editor.text(cx), "one.co\ntwo\nthree\n");
|
assert_eq!(editor.text(cx), "one.co\ntwo\nthree\n");
|
||||||
|
|
||||||
// Tabbing when there is an active suggestion inserts it.
|
// AcceptInlineCompletion when there is an active suggestion inserts it.
|
||||||
editor.tab(&Default::default(), cx);
|
editor.accept_inline_completion(&Default::default(), cx);
|
||||||
assert!(!editor.has_active_inline_completion(cx));
|
assert!(!editor.has_active_inline_completion(cx));
|
||||||
assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");
|
assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");
|
||||||
assert_eq!(editor.text(cx), "one.copilot2\ntwo\nthree\n");
|
assert_eq!(editor.text(cx), "one.copilot2\ntwo\nthree\n");
|
||||||
|
@ -550,8 +550,8 @@ mod tests {
|
||||||
assert_eq!(editor.text(cx), "fn foo() {\n \n}");
|
assert_eq!(editor.text(cx), "fn foo() {\n \n}");
|
||||||
assert_eq!(editor.display_text(cx), "fn foo() {\n let x = 4;\n}");
|
assert_eq!(editor.display_text(cx), "fn foo() {\n let x = 4;\n}");
|
||||||
|
|
||||||
// Tabbing again accepts the suggestion.
|
// Using AcceptInlineCompletion again accepts the suggestion.
|
||||||
editor.tab(&Default::default(), cx);
|
editor.accept_inline_completion(&Default::default(), cx);
|
||||||
assert!(!editor.has_active_inline_completion(cx));
|
assert!(!editor.has_active_inline_completion(cx));
|
||||||
assert_eq!(editor.text(cx), "fn foo() {\n let x = 4;\n}");
|
assert_eq!(editor.text(cx), "fn foo() {\n let x = 4;\n}");
|
||||||
assert_eq!(editor.display_text(cx), "fn foo() {\n let x = 4;\n}");
|
assert_eq!(editor.display_text(cx), "fn foo() {\n let x = 4;\n}");
|
||||||
|
|
|
@ -143,6 +143,7 @@ gpui::actions!(
|
||||||
editor,
|
editor,
|
||||||
[
|
[
|
||||||
AcceptPartialCopilotSuggestion,
|
AcceptPartialCopilotSuggestion,
|
||||||
|
AcceptInlineCompletion,
|
||||||
AcceptPartialInlineCompletion,
|
AcceptPartialInlineCompletion,
|
||||||
AddSelectionAbove,
|
AddSelectionAbove,
|
||||||
AddSelectionBelow,
|
AddSelectionBelow,
|
||||||
|
|
|
@ -4450,8 +4450,14 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn accept_inline_completion(&mut self, cx: &mut ViewContext<Self>) -> bool {
|
pub fn accept_inline_completion(
|
||||||
if let Some(completion) = self.take_active_inline_completion(cx) {
|
&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() {
|
if let Some(provider) = self.inline_completion_provider() {
|
||||||
provider.accept(cx);
|
provider.accept(cx);
|
||||||
}
|
}
|
||||||
|
@ -4463,10 +4469,6 @@ impl Editor {
|
||||||
self.insert_with_autoindent_mode(&completion.text.to_string(), None, cx);
|
self.insert_with_autoindent_mode(&completion.text.to_string(), None, cx);
|
||||||
self.refresh_inline_completion(true, cx);
|
self.refresh_inline_completion(true, cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn accept_partial_inline_completion(
|
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.
|
// Otherwise, insert a hard or soft tab.
|
||||||
let settings = buffer.settings_at(cursor, cx);
|
let settings = buffer.settings_at(cursor, cx);
|
||||||
let tab_size = if settings.hard_tabs {
|
let tab_size = if settings.hard_tabs {
|
||||||
|
|
|
@ -383,6 +383,7 @@ impl EditorElement {
|
||||||
register_action(view, cx, Editor::unique_lines_case_insensitive);
|
register_action(view, cx, Editor::unique_lines_case_insensitive);
|
||||||
register_action(view, cx, Editor::unique_lines_case_sensitive);
|
register_action(view, cx, Editor::unique_lines_case_sensitive);
|
||||||
register_action(view, cx, Editor::accept_partial_inline_completion);
|
register_action(view, cx, Editor::accept_partial_inline_completion);
|
||||||
|
register_action(view, cx, Editor::accept_inline_completion);
|
||||||
register_action(view, cx, Editor::revert_selected_hunks);
|
register_action(view, cx, Editor::revert_selected_hunks);
|
||||||
register_action(view, cx, Editor::open_active_item_in_terminal)
|
register_action(view, cx, Editor::open_active_item_in_terminal)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue