M3: choosing a tool or another tab puts the expanded All tools away

The expanded view kept covering the workspace after a control client chose a
tool (`tool=organize`) or went Home (`home`), so the chosen panel or the Home
view never showed. The same held for a document tab click, Open Recent on an
open file, and the Combine files tab.

select_tool now clears the view, so every way of choosing a tool does. The
view also remembers which tab was in front when it opened, and another tab
coming forward puts it away, whichever path brought it there.

Each new test was seen to fail with the fix reverted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
alehel
2026-10-22 17:00:41 +02:00
parent cb21b2cce4
commit 8a8bb92d33
3 changed files with 49 additions and 1 deletions
-1
View File
@@ -98,7 +98,6 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
});
});
if let Some(id) = chosen {
app.all_tools_full = false;
app.left_open = true;
app.select_tool(id);
}
+16
View File
@@ -583,6 +583,9 @@ pub struct PdfCraftApp {
/// The All tools view fills the workspace (its sidebar's expand button).
pub all_tools_full: bool,
pub all_tools_query: String,
/// The tab that showed when the expanded All tools view opened ([`Self::shown_tab`]). Another
/// tab coming to the front (Home, a document, Combine files) puts the view away.
all_tools_tab: (Option<DocId>, bool),
pub recent: Vec<RecentFile>,
/// Preferences: reopen the files that were open when PdfCraft last closed (#442).
pub reopen_last_session: bool,
@@ -987,6 +990,7 @@ impl PdfCraftApp {
all_tools_expanded: false,
all_tools_full: false,
all_tools_query: String::new(),
all_tools_tab: (None, false),
recent: Vec::new(),
reopen_last_session: false,
last_session: Default::default(),
@@ -2256,6 +2260,8 @@ impl PdfCraftApp {
/// Enter a tool from the catalogue, Home, palette or control channel. Organize is a
/// workspace, so opening its panel also opens the page grid (without toggling it off).
pub(crate) fn select_tool(&mut self, id: &'static str) {
// The tool's panel shows, not the expanded All tools view over it.
self.all_tools_full = false;
self.left = LeftPanel::Tool(id);
self.reveal_tools();
if let Some(view) = self.active.and_then(|i| self.views.get_mut(i)) {
@@ -2313,6 +2319,12 @@ impl PdfCraftApp {
self.switch_mode(Mode::AllTools, true);
}
self.all_tools_full = true;
self.all_tools_tab = self.shown_tab();
}
/// The tab at the front: the active document, or else whether Combine files shows over Home.
fn shown_tab(&self) -> (Option<DocId>, bool) {
(self.active.and_then(|i| self.views.get(i)).map(|v| v.id), self.combine_showing())
}
/// Back to the Select tool from an editing tool. A paragraph still open in the editor is
@@ -3400,6 +3412,10 @@ impl eframe::App for PdfCraftApp {
.show(ui, |ui| panels::right_panel(self, ui));
}
}
// Whichever way another tab came to the front, it shows instead of the expanded view.
if self.all_tools_full && self.all_tools_tab != self.shown_tab() {
self.all_tools_full = false;
}
let t = theme::Tokens::get(&ctx);
egui::CentralPanel::default().frame(egui::Frame::NONE.fill(t.pasteboard)).show(ui, |ui| {
if self.mode == Mode::Read {
+33
View File
@@ -207,6 +207,39 @@ fn opening_a_document_puts_the_expanded_all_tools_away() {
assert!(!app.all_tools_full);
}
#[test]
fn choosing_a_tool_puts_the_expanded_all_tools_away() {
use pdfcraft_ui_egui::LeftPanel;
let mut h = harness(|app| app.set_option("tools", "full").unwrap());
h.state_mut().set_option("tool", "organize").unwrap();
h.run_steps(3);
assert!(!h.state().all_tools_full, "the tool's panel shows, not the catalogue");
assert_eq!(h.state().left, LeftPanel::Tool("organize"));
}
#[test]
fn another_tab_coming_forward_puts_the_expanded_all_tools_away() {
// Home, through the control option.
let mut h = harness(|app| app.open_bytes("fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens"));
h.state_mut().set_option("tools", "full").unwrap();
h.run_steps(3);
assert!(h.state().all_tools_full, "the document's own tab keeps it");
h.state_mut().set_option("home", "").unwrap();
h.run_steps(3);
assert!(!h.state().all_tools_full);
h.get_by_label_contains("Welcome to PdfCraft");
// Another document's tab.
let mut h = harness(|app| {
app.open_bytes("one.pdf", None, FIXTURE.to_vec()).expect("fixture opens");
app.open_bytes("two.pdf", None, FIXTURE.to_vec()).expect("fixture opens");
});
h.state_mut().set_option("tools", "full").unwrap();
h.run_steps(3);
h.state_mut().active = Some(0);
h.run_steps(3);
assert!(!h.state().all_tools_full, "one.pdf shows, not the catalogue over it");
}
#[test]
fn expanding_all_tools_from_read_mode_restores_the_right_panel() {
use pdfcraft_ui_egui::{Mode, RightPanel};