diff --git a/crates/ui-egui/src/chrome/mode_bar.rs b/crates/ui-egui/src/chrome/mode_bar.rs index 8940a5e9a7..f6d12ac88e 100644 --- a/crates/ui-egui/src/chrome/mode_bar.rs +++ b/crates/ui-egui/src/chrome/mode_bar.rs @@ -87,6 +87,17 @@ pub(super) fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) { }; let out = strip .show_items(ui, &ModeTabs, &mut |key, _| Tab::new(tl!(MODES[*key % MODES.len()].1)).text_role(craft::theme::TypeRole::Label)); + // A click on the workspace's own tab changes no selection, so the strip reports none. With the + // Tools panel closed by its ×, that click opens the panel again, as choosing the workspace does + // (#8526); with the panel open it changes nothing, as before. + let clicked_shown = shown.is_some_and(|at| { + ui.input(|i| i.pointer.primary_clicked().then(|| i.pointer.interact_pos()).flatten()).is_some_and(|pos| { + ui.ctx().layer_id_at(pos) == Some(ui.layer_id()) && out.tab_rects.iter().any(|(key, rect)| *key == at && rect.contains(pos)) + }) + }); + if clicked_shown && !app.left_open() { + app.switch_mode(ui.ctx(), app.mode, true); + } for event in out.response.events { if let CollectionEvent::Selection(SelectionChange::Set(keys)) = event && let Some((mode, _)) = keys.last().and_then(|at| MODES.get(*at)) diff --git a/crates/ui-egui/tests/it/side_panels.rs b/crates/ui-egui/tests/it/side_panels.rs index a40ef1bbf7..0c32f246ca 100644 --- a/crates/ui-egui/tests/it/side_panels.rs +++ b/crates/ui-egui/tests/it/side_panels.rs @@ -119,3 +119,30 @@ fn f4_toggles_the_side_panel_and_shift_f4_the_tools_panel() { h.run_steps(3); h.get_by_label("Expand all tools"); } + +/// Clicks the mode bar's tab for a workspace. +fn click_mode_tab(h: &mut Harness<'static, PdfCraftApp>, label: &str) { + h.get_all_by_role_and_label(Role::Tab, label).find(|n| n.rect().bottom() < 120.0).expect("a mode tab").click(); + h.run_steps(4); +} + +/// #8526: after the × closes Edit a PDF, clicking the Edit tab, already the workspace, opens the panel again +/// rather than leaving no way back but Shift+F4. With the panel open, the click leaves it open. +#[test] +fn the_current_mode_tab_reopens_its_closed_tool_panel() { + let mut h = harness(|_| {}); + h.key_press_modifiers(egui::Modifiers::SHIFT, egui::Key::F4); + h.run_steps(3); + assert!(!h.state().left_open()); + click_mode_tab(&mut h, "All tools"); + h.get_by_label("Expand all tools"); + click_mode_tab(&mut h, "Edit"); + h.get_by_label("Close Edit a PDF").click(); + h.run_steps(4); + assert!(!h.state().left_open(), "the × closes the Edit a PDF panel"); + click_mode_tab(&mut h, "Edit"); + assert!(h.state().left_open(), "the Edit tab opens the closed panel again"); + h.get_by_label("Close Edit a PDF"); + click_mode_tab(&mut h, "Edit"); + h.get_by_label("Close Edit a PDF"); +}