Reject a keymap version nested in a binding; fix macOS keymap path in docs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sanapachandClaude Opus 5.5 committed 2026-11-19 15:26:30 +02:00
1 parent df171208eb
commit df7ad3c8b7
4 files changed
+50 -8

No files matched your search

+6 -4
View File
@@ -1,11 +1,13 @@
# Default keybindings for furumi.
#
# To customize, copy entries into <config dir>/furumi/keymap.toml
# (~/.config/furumi/keymap.toml on Linux/macOS). A user binding replaces the
# default binding with the same key sequence and context.
# To customize, copy entries into keymap.toml in the platform config dir
# (~/.config/furumi/keymap.toml on Linux,
# ~/Library/Application Support/furumi/keymap.toml on macOS). A user binding
# replaces the default binding with the same key sequence and context.
#
# version: keymap format version; put `version = 2` at the top of your file,
# before the first [[keymaps]] entry. Version 2 numbers tabs in this order:
# before the first [[keymaps]] entry (after one, TOML attaches it to that
# entry and the file is rejected). Version 2 numbers tabs in this order:
# GoToTab = 0 Library, 1 Playlists, 2 Queue, 3 Podcasts, 4 Settings, 5 Logs.
# A file without `version` is treated as the older layout and its GoToTab
# indices are adapted in memory (3 -> 4 Settings, 4 -> 5 Logs, and 5 -> 3
+34
View File
@@ -62,6 +62,11 @@ struct RawBinding {
command: Action,
#[serde(default)]
context: KeyContext,
/// Never valid here: a `version = N` line written after a `[[keymaps]]`
/// header lands inside that entry. Caught so the file is not silently
/// treated as legacy (and its tab indices remapped) despite the version.
#[serde(default)]
version: Option<toml::Value>,
}
#[derive(Debug, Default, Deserialize)]
@@ -369,6 +374,11 @@ fn parse_file(text: &str) -> Result<(Option<u32>, Vec<Binding>)> {
.keymaps
.into_iter()
.map(|raw| {
if raw.version.is_some() {
bail!(
"`version` must be a top-level key placed before the first [[keymaps]] entry"
);
}
let keys = parse_sequence(&raw.key_sequence)
.with_context(|| format!("bad key_sequence {:?}", raw.key_sequence))?;
Ok(Binding {
@@ -795,6 +805,30 @@ mod tests {
assert!(user.notice.unwrap().contains("newer"));
}
#[test]
fn version_inside_a_keymaps_entry_is_rejected() {
// Appended at the end, TOML puts `version` into the last entry; the
// file must not silently fall back to the legacy remap.
let err = parse_user_keymap(
"[[keymaps]]\nkey_sequence = \"4\"\ncommand = { GoToTab = 3 }\nversion = 2\n",
)
.err()
.expect("misplaced version must be rejected");
assert!(
format!("{err:#}").contains("before the first [[keymaps]]"),
"{err:#}"
);
}
#[test]
fn unknown_keys_in_keymaps_entries_are_still_ignored() {
let user = parse_user_keymap(
"version = 2\n[[keymaps]]\nkey_sequence = \"4\"\ncommand = { GoToTab = 3 }\nnote = \"mine\"\n",
)
.unwrap();
assert_eq!(go_to_tab_indices(&user.bindings), [3]);
}
#[test]
fn keymap_version_zero_is_rejected() {
assert!(parse_user_keymap("version = 0").is_err());