Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

A classic menu command with its access key in brackets is not listed twice (902)

gelenmedyaad1c4eeb14ba
diff --git a/crates/rf-app/src/ctx_menu.rs b/crates/rf-app/src/ctx_menu.rs
index 2ad96393..282f1f20 100644
--- a/crates/rf-app/src/ctx_menu.rs
+++ b/crates/rf-app/src/ctx_menu.rs
@@ -1724,7 +1724,9 @@ fn item_title(it: &Item) -> Option<String> {
/// keys, case, and a trailing ellipsis): one of each pair goes, the classic one unless `prefer_classic`. Rows without a twin and
/// separators always stay.
fn twins(new: &[Option<String>], classic: &[Option<String>], prefer_classic: bool) -> (Vec<bool>, Vec<bool>) {
- let plain = |s: &String| s.replace('&', "").trim().trim_end_matches("...").trim_end_matches('…').trim().to_lowercase();
+ // (also without an access key written after the title in brackets, as East Asian menus have it: "Bandizip(&B)", issue 902:
+ // the classic Bandizip row was never taken for the packaged one's twin, and both were listed)
+ let plain = |s: &String| strip_bracket_key(&s.replace('&', "")).trim().trim_end_matches("...").trim_end_matches('…').trim().to_lowercase();
let n: Vec<Option<String>> = new.iter().map(|t| t.as_ref().map(plain).filter(|t| !t.is_empty())).collect();
let c: Vec<Option<String>> = classic.iter().map(|t| t.as_ref().map(plain).filter(|t| !t.is_empty())).collect();
let in_c = |t: &Option<String>| t.is_some() && c.contains(t);
@@ -1732,6 +1734,18 @@ fn twins(new: &[Option<String>], classic: &[Option<String>], prefer_classic: boo
(n.iter().map(|t| !(prefer_classic && in_c(t))).collect(), c.iter().map(|t| prefer_classic || !in_n(t)).collect())
}
+/// A title without a one-letter access key in brackets at its end ("Bandizip (B)" -> "Bandizip"), with the `&` already gone. Pure.
+fn strip_bracket_key(title: &str) -> &str {
+ let t = title.trim_end();
+ let cut = |open: char, close: char| {
+ let inner = t.strip_suffix(close)?;
+ let at = inner.rfind(open)?;
+ let key = &inner[at + open.len_utf8()..];
+ (key.chars().count() == 1 && key.chars().all(|c| c.is_alphanumeric())).then(|| t[..at].trim_end())
+ };
+ cut('(', ')').or_else(|| cut('(', ')')).unwrap_or(t)
+}
+
/// No separator first, last, or after another one (rows were taken out between them).
fn tidy_separators(items: Vec<Item>) -> Vec<Item> {
let mut out: Vec<Item> = Vec::with_capacity(items.len());
@@ -1791,6 +1805,11 @@ mod twin_tests {
assert_eq!(twins(&t(&["Open"]), &t(&["Open with Code"]), false), (vec![true], vec![true]));
// an ellipsis and the case are not a difference; separators never count as twins
assert_eq!(twins(&t(&["Share…", ""]), &t(&["share...", ""]), false), (vec![true, true], vec![false, true]));
+ // issue 902: an East Asian menu writes the access key after the title
+ assert_eq!(twins(&t(&["Bandizip"]), &t(&["Bandizip(&B)"]), false), (vec![true], vec![false]));
+ assert_eq!(twins(&t(&["Bandizip"]), &t(&["Bandizip (&B)"]), false), (vec![true], vec![false]));
+ // (a real word in brackets is no access key)
+ assert_eq!(twins(&t(&["Open"]), &t(&["Open (new)"]), false), (vec![true], vec![true]));
}
}