keymap_ui: Support unbinding non-user defined keybindings (#34318)

Closes #ISSUE

Makes it so that `KeymapFile::update_keybinding` treats removals of
bindings that weren't user-defined as creating a new binding to
`zed::NoAction`.


Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Ben Kunkle 2025-07-11 16:23:14 -05:00 committed by GitHub
parent c3edc2cfc1
commit 206cce6783
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 73 additions and 47 deletions

View file

@ -607,8 +607,8 @@ impl KeymapFile {
mut keymap_contents: String,
tab_size: usize,
) -> Result<String> {
// if trying to replace a keybinding that is not user-defined, treat it as an add operation
match operation {
// if trying to replace a keybinding that is not user-defined, treat it as an add operation
KeybindUpdateOperation::Replace {
target_keybind_source: target_source,
source,
@ -616,6 +616,16 @@ impl KeymapFile {
} if target_source != KeybindSource::User => {
operation = KeybindUpdateOperation::Add(source);
}
// if trying to remove a keybinding that is not user-defined, treat it as creating a binding
// that binds it to `zed::NoAction`
KeybindUpdateOperation::Remove {
mut target,
target_keybind_source,
} if target_keybind_source != KeybindSource::User => {
target.action_name = gpui::NoAction.name();
target.input.take();
operation = KeybindUpdateOperation::Add(target);
}
_ => {}
}
@ -623,14 +633,7 @@ impl KeymapFile {
// We don't want to modify the file if it's invalid.
let keymap = Self::parse(&keymap_contents).context("Failed to parse keymap")?;
if let KeybindUpdateOperation::Remove {
target,
target_keybind_source,
} = operation
{
if target_keybind_source != KeybindSource::User {
anyhow::bail!("Cannot remove non-user created keybinding. Not implemented yet");
}
if let KeybindUpdateOperation::Remove { target, .. } = operation {
let target_action_value = target
.action_value()
.context("Failed to generate target action JSON value")?;