From add0dad6d73ae69e113389576ded8b9cbd73272e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 11 Apr 2022 17:17:03 -0700 Subject: [PATCH] Use '*' to represent the default context in keymap files Co-authored-by: Keith Simmons --- assets/keymaps/default.json | 2 +- crates/settings/src/keymap_file.rs | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 6b5511dbce460a0c12ade81d1d8b923ff03efe5a..dbfbcc03aba54c68a42b822ee46f84ae9e792fcd 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -1,5 +1,5 @@ { - "": { + "*": { "ctrl-alt-cmd-f": "workspace::FollowNextCollaborator", "cmd-s": "workspace::Save", "cmd-alt-i": "workspace::DebugElements", diff --git a/crates/settings/src/keymap_file.rs b/crates/settings/src/keymap_file.rs index 97ea45138a4a53dbced1c137983d03c1be149edc..d82c7ef8f6f4aefad0abe792dc4bfccb147071f6 100644 --- a/crates/settings/src/keymap_file.rs +++ b/crates/settings/src/keymap_file.rs @@ -29,16 +29,17 @@ impl KeymapFile { pub fn add(self, cx: &mut MutableAppContext) -> Result<()> { for (context, actions) in self.0 { - let context = if context.is_empty() { - None - } else { - Some(context) - }; + let context = if context == "*" { None } else { Some(context) }; cx.add_bindings( actions .into_iter() .map(|(keystroke, action)| { let action = action.get(); + + // This is a workaround for a limitation in serde: serde-rs/json#497 + // We want to deserialize the action data as a `RawValue` so that we can + // deserialize the action itself dynamically directly from the JSON + // string. But `RawValue` currently does not work inside of an untagged enum. let action = if action.starts_with('[') { let ActionWithData(name, data) = serde_json::from_str(action)?; cx.deserialize_action(name, Some(data.get()))