diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-26 18:13:31 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-26 18:13:31 +0300 |
| commit | 32e3d7b7fd215efd021d8869207b018edd0c2c83 (patch) | |
| tree | ab88c756a303f54d38bb7fe7b2743e6053f0ecb2 /src/ui | |
| parent | b44ca3b39ea4e9d90cc85dfc4a749ceddc09d19e (diff) | |
fix: compact indexed keybind help ranges
refs #817
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/keybind_help.rs | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/ui/keybind_help.rs b/src/ui/keybind_help.rs index 76a68f0d..8385af36 100644 --- a/src/ui/keybind_help.rs +++ b/src/ui/keybind_help.rs @@ -29,25 +29,34 @@ fn keybind_label(bindings: &crate::config::ActionKeybinds) -> String { fn indexed_label(bindings: &[crate::config::IndexedKeybind]) -> String { if bindings.is_empty() { - "unset".to_string() - } else if bindings.len() == 9 { - let first = &bindings[0].label; - if first.ends_with('1') { - format!("{}1..9", first.trim_end_matches('1')) + return "unset".to_string(); + } + + let mut parts = Vec::new(); + let mut index = 0; + while index < bindings.len() { + if let Some(prefix) = indexed_range_prefix(&bindings[index..]) { + parts.push(format!("{prefix}1..9")); + index += 9; } else { - bindings - .iter() - .map(|binding| binding.label.clone()) - .collect::<Vec<_>>() - .join(" / ") + parts.push(bindings[index].label.clone()); + index += 1; + } + } + + parts.join(" / ") +} + +fn indexed_range_prefix(bindings: &[crate::config::IndexedKeybind]) -> Option<&str> { + let run = bindings.get(..9)?; + let prefix = run[0].label.strip_suffix('1')?; + for (offset, binding) in run.iter().enumerate() { + let digit = char::from(b'1' + offset as u8); + if binding.label.strip_suffix(digit) != Some(prefix) { + return None; } - } else { - bindings - .iter() - .map(|binding| binding.label.clone()) - .collect::<Vec<_>>() - .join(" / ") } + Some(prefix) } pub(super) fn keybind_help_groups(app: &AppState) -> Vec<HelpGroup> { |
