fix(ui): the current mode tab reopens its closed tool panel

A click on the tab already selected changes no selection, so the mode
strip reported nothing: once Edit a PDF was closed with its ×, the Edit
tab did nothing and only Shift+F4 brought the panel back (#8526).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit f54e48bd5c)
This commit is contained in:
sixparks authored and FredApps committed 2026-12-01 08:57:21 +01:00
1 parent 55f87b3885
commit eb74bfb9cf
2 files changed
+38

No files matched your search

+11
View File
@@ -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))
+27
View File
@@ -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");
}