fix(ui): preserve alignment shortcuts for CLI consumers

This commit is contained in:
AnhNgoo
2026-11-02 13:43:29 +07:00
parent e945d7b76d
commit b408b70986
3 changed files with 14 additions and 4 deletions
+9 -1
View File
@@ -64,7 +64,15 @@ pub struct CommandInfo {
impl CommandInfo {
/// Format the portable shortcut notation for the runtime operating system.
pub fn shortcut_for_platform(&self, mac: bool) -> Option<String> {
let keys = if mac { self.shortcut_mac.or(self.shortcut) } else { self.shortcut }?;
let keys = if mac {
self.shortcut_mac.or(self.shortcut)
} else if self.shortcut_mac.is_some() && self.shortcut_mac == self.shortcut {
// An identical Mac override marks a Mac-only display shortcut.
// The portable field remains unchanged for legacy CLI consumers.
None
} else {
self.shortcut
}?;
if mac {
return Some(keys.to_owned());
}
+2 -2
View File
@@ -89,11 +89,11 @@ pub fn specs() -> Vec<CommandSpec> {
// Alignment
CommandSpec {
shortcut_mac: Some("Cmd+L"),
..cmd!("home.alignLeft", "Align Left", ["Home", "Alignment"], None, "{range?}", has_doc, |s, p| halign(s, p, HAlign::Left))
..cmd!("home.alignLeft", "Align Left", ["Home", "Alignment"], Some("Cmd+L"), "{range?}", has_doc, |s, p| halign(s, p, HAlign::Left))
},
CommandSpec {
shortcut_mac: Some("Cmd+E"),
..cmd!("home.alignCenter", "Center", ["Home", "Alignment"], None, "{range?}", has_doc, |s, p| halign(s, p, HAlign::Center))
..cmd!("home.alignCenter", "Center", ["Home", "Alignment"], Some("Cmd+E"), "{range?}", has_doc, |s, p| halign(s, p, HAlign::Center))
},
cmd!("home.alignRight", "Align Right", ["Home", "Alignment"], None, "{range?}", has_doc, |s, p| halign(s, p, HAlign::Right)),
cmd!("home.justify", "Justify", ["Home", "Alignment"], None, "{range?}", has_doc, |s, p| halign(s, p, HAlign::Justify)),
+3 -1
View File
@@ -177,7 +177,9 @@ fn command_palette_shortcuts_come_from_engine_metadata() {
assert_eq!(command.shortcut_for_platform(false), other.map(str::to_string), "{id}: Windows/Linux");
}
for (id, legacy) in [("data.group", "Alt+Shift+Right"), ("data.ungroup", "Alt+Shift+Left")] {
for (id, legacy) in
[("data.group", "Alt+Shift+Right"), ("data.ungroup", "Alt+Shift+Left"), ("home.alignLeft", "Cmd+L"), ("home.alignCenter", "Cmd+E")]
{
let command = commands.iter().find(|c| c.id == id).unwrap();
assert_eq!(command.shortcut, Some(legacy), "{id}: legacy CLI shortcut");
}