diff --git a/crates/automation/src/ui/actions/menu.rs b/crates/automation/src/ui/actions/menu.rs index e61555df8..c18c935c7 100644 --- a/crates/automation/src/ui/actions/menu.rs +++ b/crates/automation/src/ui/actions/menu.rs @@ -133,9 +133,9 @@ impl ActionsPanelCommands { } /// The rows of the Actions panel's menu, for the dock's `PanelMenu`: New Action…, New Set…, Set -/// Options…, Play, Start and Stop Recording, Delete, Insert Stop…, Batch…, Load and Save Actions… -/// and Button Mode, in groups. -pub fn panel_rows() -> Vec { +/// Options…, Play, Start Recording (Stop Recording while `recording`), Delete, Insert Stop…, Batch…, +/// Load and Save Actions… and Button Mode, in groups. +pub fn panel_rows(recording: bool) -> Vec { let command = |command: ActionsPanelCommands| PanelRow::Command(CommandRef::from(command)); vec![ command(ActionsPanelCommands::NewAction), @@ -143,8 +143,7 @@ pub fn panel_rows() -> Vec { command(ActionsPanelCommands::SetOptions), PanelRow::Separator, command(ActionsPanelCommands::Play), - command(ActionsPanelCommands::StartRecording), - command(ActionsPanelCommands::StopRecording), + command(if recording { ActionsPanelCommands::StopRecording } else { ActionsPanelCommands::StartRecording }), command(ActionsPanelCommands::Delete), PanelRow::Separator, command(ActionsPanelCommands::InsertStop), diff --git a/crates/menu/tests/it/main.rs b/crates/menu/tests/it/main.rs index a61f6d5ef..dccdaddd3 100644 --- a/crates/menu/tests/it/main.rs +++ b/crates/menu/tests/it/main.rs @@ -1,6 +1,7 @@ //! The integration binary of craft-menu: every test is a registered trial. mod layout; +mod mnemonic; mod native; mod sample; mod shortcuts; diff --git a/crates/menu/tests/it/mnemonic.rs b/crates/menu/tests/it/mnemonic.rs new file mode 100644 index 000000000..d92aad0ce --- /dev/null +++ b/crates/menu/tests/it/mnemonic.rs @@ -0,0 +1,25 @@ +//! A label with no typable letter takes its English label's letter as its mnemonic, shown after it: "文件(F)". + +use craft_menu::{CommandRef, Labeled, MenuBarUi, Row, from_items}; +use craft_ui::testing::{Fixture, trial}; +use egui::{Key, Modifiers}; + +#[trial] +fn a_cjk_title_shows_its_english_letter_and_the_letter_opens_it() { + let bar = from_items(&["文件"], &[Row::new(&["文件"], CommandRef::new("file.new"), "新建")]); + let english = |labeled: Labeled<'_>| match labeled { + Labeled::Title("文件") => Some("File".to_owned()), + Labeled::Command(command) if *command == CommandRef::new("file.new") => Some("New".to_owned()), + _ => None, + }; + let mut fixture = Fixture::new(move |ui| { + MenuBarUi::new(&bar).english(&english).show(ui); + }); + fixture.settle(); + assert!(fixture.by_label("文件(F)").is_some(), "the title shows the English letter after it"); + fixture.key(Key::F10, Modifiers::NONE); + fixture.settle(); + fixture.key(Key::F, Modifiers::NONE); + fixture.settle(); + assert!(fixture.by_label("新建(N)").is_some(), "F opens the title's menu, whose row shows its own English letter"); +} diff --git a/crates/ui-patterns/src/patterns/panels/palette.rs b/crates/ui-patterns/src/patterns/panels/palette.rs index 733a190f3..e276bd177 100644 --- a/crates/ui-patterns/src/patterns/panels/palette.rs +++ b/crates/ui-patterns/src/patterns/panels/palette.rs @@ -62,9 +62,9 @@ impl crate::contract::Outcome for PaletteOutput { /// A search over the app's commands in a centred modal box: a search field over the matching commands. /// -/// - Entries: [`HelpEntry`]s, found by label, English label or menu path and ranked by [`search_order`]. A row shows -/// the label, the menu path under it and the command's chord at the end; a disabled command is listed and does -/// not run. +/// - Entries: [`HelpEntry`]s, found by label, English label or menu path and ranked by [`search_order`]. A row is one +/// line: the label, the menu path (dropped when the label would get too narrow) and the command's chord at the end. +/// A disabled command is listed and does not run. /// - Empty query: the commands last run, newest first (the `recents` binding), else the first entries. /// - Keys: the field keeps the focus; Up, Down, Page Up, Page Down move the active row (Up and Down wrap at the ends), /// Enter picks it, Escape clears @@ -222,14 +222,17 @@ struct RowData { } impl RowData { + /// One line: the label, then the menu path, which drops out when the label would get too narrow, and the chord + /// at the end. fn row(&self) -> ListRow<'static> { let row = ListRow::new(self.label.clone()).option().enabled(self.enabled); - let row = match &self.path { - Some(path) => row.detail(path.clone()), + // The first trailing item is the outermost: the chord ends the row and the path sits before it. + let row = match &self.chord { + Some(chord) => row.trailing(chord.clone()), None => row, }; - match &self.chord { - Some(chord) => row.trailing(chord.clone()), + match &self.path { + Some(path) => row.optional(path.clone()), None => row, } } diff --git a/crates/ui-widgets/tests/it/menu/rows.rs b/crates/ui-widgets/tests/it/menu/rows.rs index d61a2c6df..1d0a21aae 100644 --- a/crates/ui-widgets/tests/it/menu/rows.rs +++ b/crates/ui-widgets/tests/it/menu/rows.rs @@ -41,3 +41,28 @@ fn a_row_shows_its_tooltip_when_the_pointer_rests_on_it_in_an_open_menu() { fixture.settle(); assert!(fixture.texts().iter().any(|run| run.text == "Take back the last change"), "the row's tooltip shows"); } + +#[trial] +fn a_letter_no_row_takes_while_a_menu_is_open_does_not_reach_the_text_field_under_it() { + let text = std::rc::Rc::new(std::cell::RefCell::new("hello".to_owned())); + let held = text.clone(); + let mut fixture = Fixture::new(move |ui| { + let mut value = held.borrow_mut(); + let field = craft_ui::text::TextField::new("Name", craft_ui::contract::Bind::bound(&mut *value)).show(ui); + Menu::context("Field menu", &field.response).show(ui, |ui, _| { + MenuItem::new("Copy").show(ui); + MenuItem::new("Paste").show(ui); + }); + }); + fixture.settle(); + let at = fixture.by_label("Name").expect("the field").center(); + fixture.click_at(at); + fixture.settle(); + fixture.frame(vec![pointer::secondary(at, true)]); + fixture.frame(vec![pointer::secondary(at, false)]); + fixture.settle(); + assert!(fixture.by_label("Copy").is_some(), "the context menu is open over the field"); + fixture.type_text("q"); + fixture.settle(); + assert_eq!(*text.borrow(), "hello", "the letter does not reach the field"); +}