keymap_ui: Ensure keybind with empty arguments can be saved (#36393)

Follow up to #36278 to ensure this bug is actually fixed. Also fixes
this on two layers and adds a test for the lower layer, as we cannot
properly test it in the UI.

Furthermore, this improves the error message to show some more context
and ensures the status toast is actually only shown when the keybind was
successfully updated: Before, we would show the success toast whilst
also showing an error in the editor.

Lastly, this also fixes some issues with the status toast (and
animations) where no status toast or no animation would show in certain
scenarios.

Release Notes:

- N/A
This commit is contained in:
Finn Evers 2025-08-18 13:01:32 +02:00 committed by GitHub
parent d83f341d27
commit 843336970a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 93 additions and 74 deletions

View file

@ -928,14 +928,14 @@ impl<'a> KeybindUpdateTarget<'a> {
}
let action_name: Value = self.action_name.into();
let value = match self.action_arguments {
Some(args) => {
Some(args) if !args.is_empty() => {
let args = serde_json::from_str::<Value>(args)
.context("Failed to parse action arguments as JSON")?;
serde_json::json!([action_name, args])
}
None => action_name,
_ => action_name,
};
return Ok(value);
Ok(value)
}
fn keystrokes_unparsed(&self) -> String {
@ -1084,6 +1084,24 @@ mod tests {
.unindent(),
);
check_keymap_update(
"[]",
KeybindUpdateOperation::add(KeybindUpdateTarget {
keystrokes: &parse_keystrokes("ctrl-a"),
action_name: "zed::SomeAction",
context: None,
action_arguments: Some(""),
}),
r#"[
{
"bindings": {
"ctrl-a": "zed::SomeAction"
}
}
]"#
.unindent(),
);
check_keymap_update(
r#"[
{