Merge pull request #9525

This commit is contained in:
autocraft-bot[bot]
2026-12-06 02:18:37 +00:00
2 changed files with 31 additions and 8 deletions
+10 -2
View File
@@ -149,6 +149,15 @@ const LINKED_EDIT: [craft::ui::runtime::commands::EditCommands; 5] = {
[Cut, Copy, Paste, Undo, Redo]
};
/// Customize Keyboard's path fallback for commands defined by the framework, looking up `id` in `registry`.
pub(crate) fn linked_command_tab_in(id: &str, registry: &wordcraft_engine::Registry) -> Option<&'static str> {
LINKED_EDIT
.iter()
.any(|command| command.id() == id)
.then(|| registry.get(id).and_then(|spec| location_path(spec.location)).and_then(|path| path.first().copied()))
.flatten()
}
/// Customize Keyboard's path fallback for commands defined by the framework. Its category
/// filters are function pointers, so keep only the built-in registry's linked tab names.
pub(crate) fn linked_command_tab(id: &str) -> Option<&'static str> {
@@ -156,8 +165,7 @@ pub(crate) fn linked_command_tab(id: &str) -> Option<&'static str> {
let registry = wordcraft_engine::cmd::registry();
LINKED_EDIT.map(|command| {
let id = command.id();
let tab = registry.get(id).and_then(|spec| location_path(spec.location)).and_then(|path| path.first().copied());
(id, tab)
(id, linked_command_tab_in(id, &registry))
})
});
TABS.iter().find(|(linked, _)| *linked == id).and_then(|(_, tab)| *tab)
@@ -50,14 +50,13 @@ fn assignable(binding: &Binding) -> bool {
chord.mods.cmd || chord.mods.ctrl || chord.mods.alt || chord.is_function_key()
}
fn tab_with(def: &CommandDef, linked_tab: impl FnOnce(&str) -> Option<&'static str>) -> &str {
def.paths.first().and_then(|path| path.first()).map(String::as_str).or_else(|| linked_tab(&def.command.id)).unwrap_or_default()
}
/// The ribbon tab a command lives on, in English (the first part of its path).
fn tab(def: &CommandDef) -> &str {
def.paths
.first()
.and_then(|path| path.first())
.map(String::as_str)
.or_else(|| crate::app::command_board::linked_command_tab(&def.command.id))
.unwrap_or_default()
tab_with(def, crate::app::command_board::linked_command_tab)
}
/// Tabs that come up with the selection or a view, besides the engine's contextual ones; they share one Categories entry.
@@ -330,6 +329,22 @@ mod tests {
assert_eq!(areas.last().map(|a| a.id), Some("All Commands"), "All Commands comes last");
}
/// #9401 / #9183: a linked edit command's fallback tab comes from the registry location, so moving
/// `edit.copy` to another tab in the registry moves its Customize Keyboard category too.
#[test]
fn linked_command_tab_follows_the_registry_location() {
use craft::keymap::{CommandDef, Scope};
use wordcraft_engine::{CommandSpec, Registry};
let copy = CommandDef::new(CommandRef::new("edit.copy"), "Copy", Scope::app());
let builtin = wordcraft_engine::cmd::registry();
assert_eq!(super::tab_with(&copy, |id| crate::app::command_board::linked_command_tab_in(id, &builtin)), "Home");
let moved_spec = builtin.get("edit.copy").expect("edit.copy in registry");
let moved = Registry::new(vec![CommandSpec { location: "Review › Clipboard", ..*moved_spec }]);
assert_eq!(super::tab_with(&copy, |id| crate::app::command_board::linked_command_tab_in(id, &moved)), "Review");
}
/// #7971: under another language, and for the SmartArt tab that shows as "Diagram Design", commands still land
/// under their tab (the catalog keeps English paths; only the display is translated).
#[test]