keymap ui: Fix remove key mapping bug (#34683)
Release Notes: - N/A --------- Co-authored-by: Ben Kunkle <ben@zed.dev>
This commit is contained in:
parent
e1d28ff957
commit
fd64ee1bb6
2 changed files with 45 additions and 2 deletions
|
@ -1623,4 +1623,44 @@ mod tests {
|
||||||
.unindent(),
|
.unindent(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_keymap_remove() {
|
||||||
|
zlog::init_test();
|
||||||
|
|
||||||
|
check_keymap_update(
|
||||||
|
r#"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"context": "Editor",
|
||||||
|
"bindings": {
|
||||||
|
"cmd-k cmd-u": "editor::ConvertToUpperCase",
|
||||||
|
"cmd-k cmd-l": "editor::ConvertToLowerCase",
|
||||||
|
"cmd-[": "pane::GoBack",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
"#,
|
||||||
|
KeybindUpdateOperation::Remove {
|
||||||
|
target: KeybindUpdateTarget {
|
||||||
|
context: Some("Editor"),
|
||||||
|
keystrokes: &parse_keystrokes("cmd-k cmd-l"),
|
||||||
|
action_name: "editor::ConvertToLowerCase",
|
||||||
|
action_arguments: None,
|
||||||
|
},
|
||||||
|
target_keybind_source: KeybindSource::User,
|
||||||
|
},
|
||||||
|
r#"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"context": "Editor",
|
||||||
|
"bindings": {
|
||||||
|
"cmd-k cmd-u": "editor::ConvertToUpperCase",
|
||||||
|
"cmd-[": "pane::GoBack",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,6 +190,7 @@ fn replace_value_in_json_text(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut removed_comma = false;
|
||||||
// Look backward for a preceding comma first
|
// Look backward for a preceding comma first
|
||||||
let preceding_text = text.get(0..removal_start).unwrap_or("");
|
let preceding_text = text.get(0..removal_start).unwrap_or("");
|
||||||
if let Some(comma_pos) = preceding_text.rfind(',') {
|
if let Some(comma_pos) = preceding_text.rfind(',') {
|
||||||
|
@ -197,10 +198,12 @@ fn replace_value_in_json_text(
|
||||||
let between_comma_and_key = text.get(comma_pos + 1..removal_start).unwrap_or("");
|
let between_comma_and_key = text.get(comma_pos + 1..removal_start).unwrap_or("");
|
||||||
if between_comma_and_key.trim().is_empty() {
|
if between_comma_and_key.trim().is_empty() {
|
||||||
removal_start = comma_pos;
|
removal_start = comma_pos;
|
||||||
|
removed_comma = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(remaining_text) = text.get(existing_value_range.end..)
|
||||||
if let Some(remaining_text) = text.get(existing_value_range.end..) {
|
&& !removed_comma
|
||||||
|
{
|
||||||
let mut chars = remaining_text.char_indices();
|
let mut chars = remaining_text.char_indices();
|
||||||
while let Some((offset, ch)) = chars.next() {
|
while let Some((offset, ch)) = chars.next() {
|
||||||
if ch == ',' {
|
if ch == ',' {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue