mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 02:17:35 +03:00
vim: Disable inline completions if not Insert/Replace mode (#17154)
This is a follow-up to - https://github.com/zed-industries/zed/pull/17137 - https://github.com/zed-industries/zed/pull/17138 (revert of #17137) and it does what I originally thought I wouldn't have to do: add another boolean to `Editor`. cc @ConradIrwin Release Notes: - Fixed inline completions (Copilot or Supermaven) showing up in Vim's normal mode.
This commit is contained in:
parent
32e96e126f
commit
eb7367d8f2
@ -556,6 +556,9 @@ pub struct Editor {
|
|||||||
hovered_link_state: Option<HoveredLinkState>,
|
hovered_link_state: Option<HoveredLinkState>,
|
||||||
inline_completion_provider: Option<RegisteredInlineCompletionProvider>,
|
inline_completion_provider: Option<RegisteredInlineCompletionProvider>,
|
||||||
active_inline_completion: Option<(Inlay, Option<Range<Anchor>>)>,
|
active_inline_completion: Option<(Inlay, Option<Range<Anchor>>)>,
|
||||||
|
// enable_inline_completions is a switch that Vim can use to disable
|
||||||
|
// inline completions based on its mode.
|
||||||
|
enable_inline_completions: bool,
|
||||||
show_inline_completions_override: Option<bool>,
|
show_inline_completions_override: Option<bool>,
|
||||||
inlay_hint_cache: InlayHintCache,
|
inlay_hint_cache: InlayHintCache,
|
||||||
expanded_hunks: ExpandedHunks,
|
expanded_hunks: ExpandedHunks,
|
||||||
@ -1913,6 +1916,7 @@ impl Editor {
|
|||||||
next_editor_action_id: EditorActionId::default(),
|
next_editor_action_id: EditorActionId::default(),
|
||||||
editor_actions: Rc::default(),
|
editor_actions: Rc::default(),
|
||||||
show_inline_completions_override: None,
|
show_inline_completions_override: None,
|
||||||
|
enable_inline_completions: true,
|
||||||
custom_context_menu: None,
|
custom_context_menu: None,
|
||||||
show_git_blame_gutter: false,
|
show_git_blame_gutter: false,
|
||||||
show_git_blame_inline: false,
|
show_git_blame_inline: false,
|
||||||
@ -2277,6 +2281,10 @@ impl Editor {
|
|||||||
self.input_enabled = input_enabled;
|
self.input_enabled = input_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_inline_completions_enabled(&mut self, enabled: bool) {
|
||||||
|
self.enable_inline_completions = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_autoindent(&mut self, autoindent: bool) {
|
pub fn set_autoindent(&mut self, autoindent: bool) {
|
||||||
if autoindent {
|
if autoindent {
|
||||||
self.autoindent_mode = Some(AutoindentMode::EachLine);
|
self.autoindent_mode = Some(AutoindentMode::EachLine);
|
||||||
@ -4977,6 +4985,7 @@ impl Editor {
|
|||||||
let (buffer, cursor_buffer_position) =
|
let (buffer, cursor_buffer_position) =
|
||||||
self.buffer.read(cx).text_anchor_for_position(cursor, cx)?;
|
self.buffer.read(cx).text_anchor_for_position(cursor, cx)?;
|
||||||
if !user_requested
|
if !user_requested
|
||||||
|
&& self.enable_inline_completions
|
||||||
&& !self.should_show_inline_completions(&buffer, cursor_buffer_position, cx)
|
&& !self.should_show_inline_completions(&buffer, cursor_buffer_position, cx)
|
||||||
{
|
{
|
||||||
self.discard_inline_completion(false, cx);
|
self.discard_inline_completion(false, cx);
|
||||||
@ -4997,7 +5006,9 @@ impl Editor {
|
|||||||
let cursor = self.selections.newest_anchor().head();
|
let cursor = self.selections.newest_anchor().head();
|
||||||
let (buffer, cursor_buffer_position) =
|
let (buffer, cursor_buffer_position) =
|
||||||
self.buffer.read(cx).text_anchor_for_position(cursor, cx)?;
|
self.buffer.read(cx).text_anchor_for_position(cursor, cx)?;
|
||||||
if !self.should_show_inline_completions(&buffer, cursor_buffer_position, cx) {
|
if !self.enable_inline_completions
|
||||||
|
|| !self.should_show_inline_completions(&buffer, cursor_buffer_position, cx)
|
||||||
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1061,6 +1061,7 @@ impl Vim {
|
|||||||
editor.set_input_enabled(vim.editor_input_enabled());
|
editor.set_input_enabled(vim.editor_input_enabled());
|
||||||
editor.set_autoindent(vim.should_autoindent());
|
editor.set_autoindent(vim.should_autoindent());
|
||||||
editor.selections.line_mode = matches!(vim.mode, Mode::VisualLine);
|
editor.selections.line_mode = matches!(vim.mode, Mode::VisualLine);
|
||||||
|
editor.set_inline_completions_enabled(matches!(vim.mode, Mode::Insert | Mode::Replace));
|
||||||
});
|
});
|
||||||
cx.notify()
|
cx.notify()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user