mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
vim: Don't show inline completions in normal mode (#17137)
This fixes an annoying bug I ran into, where supermaven completions would show up in normal mode. cc @ConradIrwin not sure if this is the best way to fix this, but it seems like the neatest? On one hand, I didn't want to touch into Vim from the editor, and on the other I didn't want to add another boolean on the editor that flips on when in normal mode. So instead I extended the Addon interface. Release Notes: - Fixed inline completions (Copilot or Supermaven) showing up in Vim's normal mode.
This commit is contained in:
parent
6403385468
commit
9206561662
@ -470,6 +470,9 @@ struct BufferOffset(usize);
|
|||||||
// Addons allow storing per-editor state in other crates (e.g. Vim)
|
// Addons allow storing per-editor state in other crates (e.g. Vim)
|
||||||
pub trait Addon: 'static {
|
pub trait Addon: 'static {
|
||||||
fn extend_key_context(&self, _: &mut KeyContext, _: &AppContext) {}
|
fn extend_key_context(&self, _: &mut KeyContext, _: &AppContext) {}
|
||||||
|
fn should_show_inline_completions(&self, _: &AppContext) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn to_any(&self) -> &dyn std::any::Any;
|
fn to_any(&self) -> &dyn std::any::Any;
|
||||||
}
|
}
|
||||||
@ -2340,6 +2343,11 @@ impl Editor {
|
|||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Some(provider) = self.inline_completion_provider() {
|
if let Some(provider) = self.inline_completion_provider() {
|
||||||
|
for addon in self.addons.values() {
|
||||||
|
if !addon.should_show_inline_completions(cx) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
if let Some(show_inline_completions) = self.show_inline_completions_override {
|
if let Some(show_inline_completions) = self.show_inline_completions_override {
|
||||||
show_inline_completions
|
show_inline_completions
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,8 +91,7 @@ pub fn init(cx: &mut AppContext) {
|
|||||||
VimSettings::register(cx);
|
VimSettings::register(cx);
|
||||||
VimGlobals::register(cx);
|
VimGlobals::register(cx);
|
||||||
|
|
||||||
cx.observe_new_views(|editor: &mut Editor, cx| Vim::register(editor, cx))
|
cx.observe_new_views(Vim::register).detach();
|
||||||
.detach();
|
|
||||||
|
|
||||||
cx.observe_new_views(|workspace: &mut Workspace, _| {
|
cx.observe_new_views(|workspace: &mut Workspace, _| {
|
||||||
workspace.register_action(|workspace, _: &ToggleVimMode, cx| {
|
workspace.register_action(|workspace, _: &ToggleVimMode, cx| {
|
||||||
@ -135,6 +134,11 @@ impl editor::Addon for VimAddon {
|
|||||||
self.view.read(cx).extend_key_context(key_context)
|
self.view.read(cx).extend_key_context(key_context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn should_show_inline_completions(&self, cx: &AppContext) -> bool {
|
||||||
|
let mode = self.view.read(cx).mode;
|
||||||
|
mode == Mode::Insert || mode == Mode::Replace
|
||||||
|
}
|
||||||
|
|
||||||
fn to_any(&self) -> &dyn std::any::Any {
|
fn to_any(&self) -> &dyn std::any::Any {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user