Improve handling tab when inline completion is visible (#22892)
This changes the behaviour of `<tab>` when inline completion is visible. When the cursor is before the suggested indentation level, accepting a completion should just indent. cc @nathansobo @maxdeviant Release Notes: - Changed the behavior of `<tab>` at start of line when an inline completion (Copilot, Supermaven, ...) is visible. If the cursor is before the suggested indentation, `<tab>` now indents the line instead of accepting the visible completion. Co-authored-by: Antonio <antonio@zed.dev>
This commit is contained in:
parent
6c50659c30
commit
38fbc73ac4
2 changed files with 67 additions and 1 deletions
|
@ -4571,6 +4571,23 @@ impl Editor {
|
|||
_: &AcceptInlineCompletion,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let buffer = self.buffer.read(cx);
|
||||
let snapshot = buffer.snapshot(cx);
|
||||
let selection = self.selections.newest_adjusted(cx);
|
||||
let cursor = selection.head();
|
||||
let current_indent = snapshot.indent_size_for_line(MultiBufferRow(cursor.row));
|
||||
let suggested_indents = snapshot.suggested_indents([cursor.row], cx);
|
||||
if let Some(suggested_indent) = suggested_indents.get(&MultiBufferRow(cursor.row)).copied()
|
||||
{
|
||||
if cursor.column < suggested_indent.len
|
||||
&& cursor.column <= current_indent.len
|
||||
&& current_indent.len <= suggested_indent.len
|
||||
{
|
||||
self.tab(&Default::default(), cx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if self.show_inline_completions_in_menu(cx) {
|
||||
self.hide_context_menu(cx);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue