Fix some bugs in keymap handling (#3895)
- `base_keymap` setting was not respected, now it is - without a `~/.config/zed/keymap.json` file, we would fail to load the *default* keymap Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
parent
2da314fb79
commit
5e3d4885bf
4 changed files with 71 additions and 41 deletions
|
@ -327,6 +327,7 @@ impl AppContext {
|
|||
pub fn refresh(&mut self) {
|
||||
self.pending_effects.push_back(Effect::Refresh);
|
||||
}
|
||||
|
||||
pub(crate) fn update<R>(&mut self, update: impl FnOnce(&mut Self) -> R) -> R {
|
||||
self.pending_updates += 1;
|
||||
let result = update(self);
|
||||
|
@ -840,10 +841,12 @@ impl AppContext {
|
|||
/// Update the global of the given type with a closure. Unlike `global_mut`, this method provides
|
||||
/// your closure with mutable access to the `AppContext` and the global simultaneously.
|
||||
pub fn update_global<G: 'static, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R {
|
||||
let mut global = self.lease_global::<G>();
|
||||
let result = f(&mut global, self);
|
||||
self.end_global_lease(global);
|
||||
result
|
||||
self.update(|cx| {
|
||||
let mut global = cx.lease_global::<G>();
|
||||
let result = f(&mut global, cx);
|
||||
cx.end_global_lease(global);
|
||||
result
|
||||
})
|
||||
}
|
||||
|
||||
/// Register a callback to be invoked when a global of the given type is updated.
|
||||
|
@ -941,6 +944,11 @@ impl AppContext {
|
|||
self.pending_effects.push_back(Effect::Refresh);
|
||||
}
|
||||
|
||||
pub fn clear_key_bindings(&mut self) {
|
||||
self.keymap.lock().clear();
|
||||
self.pending_effects.push_back(Effect::Refresh);
|
||||
}
|
||||
|
||||
/// Register a global listener for actions invoked via the keyboard.
|
||||
pub fn on_action<A: Action>(&mut self, listener: impl Fn(&A, &mut Self) + 'static) {
|
||||
self.global_action_listeners
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue