Use '*' to represent the default context in keymap files

Co-authored-by: Keith Simmons <keith@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-04-11 17:17:03 -07:00
parent ee3eb9658f
commit add0dad6d7
2 changed files with 7 additions and 6 deletions

View file

@ -1,5 +1,5 @@
{
"": {
"*": {
"ctrl-alt-cmd-f": "workspace::FollowNextCollaborator",
"cmd-s": "workspace::Save",
"cmd-alt-i": "workspace::DebugElements",

View file

@ -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()))