Merge pull request #1256 from zed-industries/remove-vim-commands-when-disabled
Update command palette filter from vim mode more proactively
This commit is contained in:
commit
4dafe1885a
3 changed files with 22 additions and 21 deletions
|
@ -1634,14 +1634,10 @@ impl MutableAppContext {
|
||||||
pub fn default_global<T: 'static + Default>(&mut self) -> &T {
|
pub fn default_global<T: 'static + Default>(&mut self) -> &T {
|
||||||
let type_id = TypeId::of::<T>();
|
let type_id = TypeId::of::<T>();
|
||||||
self.update(|this| {
|
self.update(|this| {
|
||||||
if !this.globals.contains_key(&type_id) {
|
if let Entry::Vacant(entry) = this.cx.globals.entry(type_id) {
|
||||||
|
entry.insert(Box::new(T::default()));
|
||||||
this.notify_global(type_id);
|
this.notify_global(type_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cx
|
|
||||||
.globals
|
|
||||||
.entry(type_id)
|
|
||||||
.or_insert_with(|| Box::new(T::default()));
|
|
||||||
});
|
});
|
||||||
self.globals.get(&type_id).unwrap().downcast_ref().unwrap()
|
self.globals.get(&type_id).unwrap().downcast_ref().unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
fn editor_created(EditorCreated(editor): &EditorCreated, cx: &mut MutableAppContext) {
|
fn editor_created(EditorCreated(editor): &EditorCreated, cx: &mut MutableAppContext) {
|
||||||
cx.update_default_global(|vim: &mut Vim, cx| {
|
cx.update_default_global(|vim: &mut Vim, cx| {
|
||||||
vim.editors.insert(editor.id(), editor.downgrade());
|
vim.editors.insert(editor.id(), editor.downgrade());
|
||||||
vim.sync_editor_options(cx);
|
vim.sync_vim_settings(cx);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ fn editor_blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut MutableAppCont
|
||||||
vim.active_editor = None;
|
vim.active_editor = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vim.sync_editor_options(cx);
|
vim.sync_vim_settings(cx);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,10 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Sync initial settings with the rest of the app
|
||||||
|
Vim::update(cx, |state, cx| state.sync_vim_settings(cx));
|
||||||
|
|
||||||
|
// Any time settings change, update vim mode to match
|
||||||
cx.observe_global::<Settings, _>(|cx| {
|
cx.observe_global::<Settings, _>(|cx| {
|
||||||
Vim::update(cx, |state, cx| {
|
Vim::update(cx, |state, cx| {
|
||||||
state.set_enabled(cx.global::<Settings>().vim_mode, cx)
|
state.set_enabled(cx.global::<Settings>().vim_mode, cx)
|
||||||
|
@ -95,23 +99,23 @@ impl Vim {
|
||||||
fn switch_mode(&mut self, mode: Mode, cx: &mut MutableAppContext) {
|
fn switch_mode(&mut self, mode: Mode, cx: &mut MutableAppContext) {
|
||||||
self.state.mode = mode;
|
self.state.mode = mode;
|
||||||
self.state.operator_stack.clear();
|
self.state.operator_stack.clear();
|
||||||
self.sync_editor_options(cx);
|
self.sync_vim_settings(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_operator(&mut self, operator: Operator, cx: &mut MutableAppContext) {
|
fn push_operator(&mut self, operator: Operator, cx: &mut MutableAppContext) {
|
||||||
self.state.operator_stack.push(operator);
|
self.state.operator_stack.push(operator);
|
||||||
self.sync_editor_options(cx);
|
self.sync_vim_settings(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pop_operator(&mut self, cx: &mut MutableAppContext) -> Operator {
|
fn pop_operator(&mut self, cx: &mut MutableAppContext) -> Operator {
|
||||||
let popped_operator = self.state.operator_stack.pop().expect("Operator popped when no operator was on the stack. This likely means there is an invalid keymap config");
|
let popped_operator = self.state.operator_stack.pop().expect("Operator popped when no operator was on the stack. This likely means there is an invalid keymap config");
|
||||||
self.sync_editor_options(cx);
|
self.sync_vim_settings(cx);
|
||||||
popped_operator
|
popped_operator
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_operator(&mut self, cx: &mut MutableAppContext) {
|
fn clear_operator(&mut self, cx: &mut MutableAppContext) {
|
||||||
self.state.operator_stack.clear();
|
self.state.operator_stack.clear();
|
||||||
self.sync_editor_options(cx);
|
self.sync_vim_settings(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn active_operator(&self) -> Option<Operator> {
|
fn active_operator(&self) -> Option<Operator> {
|
||||||
|
@ -125,21 +129,22 @@ impl Vim {
|
||||||
if enabled {
|
if enabled {
|
||||||
self.state.mode = Mode::Normal;
|
self.state.mode = Mode::Normal;
|
||||||
}
|
}
|
||||||
cx.update_default_global::<CommandPaletteFilter, _, _>(|filter, _| {
|
self.sync_vim_settings(cx);
|
||||||
if enabled {
|
|
||||||
filter.filtered_namespaces.remove("vim");
|
|
||||||
} else {
|
|
||||||
filter.filtered_namespaces.insert("vim");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
self.sync_editor_options(cx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_editor_options(&self, cx: &mut MutableAppContext) {
|
fn sync_vim_settings(&self, cx: &mut MutableAppContext) {
|
||||||
let state = &self.state;
|
let state = &self.state;
|
||||||
let cursor_shape = state.cursor_shape();
|
let cursor_shape = state.cursor_shape();
|
||||||
|
|
||||||
|
cx.update_default_global::<CommandPaletteFilter, _, _>(|filter, _| {
|
||||||
|
if self.enabled {
|
||||||
|
filter.filtered_namespaces.remove("vim");
|
||||||
|
} else {
|
||||||
|
filter.filtered_namespaces.insert("vim");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
for editor in self.editors.values() {
|
for editor in self.editors.values() {
|
||||||
if let Some(editor) = editor.upgrade(cx) {
|
if let Some(editor) = editor.upgrade(cx) {
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue