Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

fix(ui): Read mode hides the quick toolbar (#2646)

Enrico Sitac66384f92ba0
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 0acab64a0..b5db6b462 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -3893,7 +3893,10 @@ pub fn document_area(app: &mut PdfCraftApp, index: usize, ui: &mut egui::Ui) {
if copy_selected {
app.execute("edit.copy");
}
- quick_bar(app, avail, ui);
+ // Read mode hides the tools (#2646).
+ if app.mode != crate::Mode::Read {
+ quick_bar(app, avail, ui);
+ }
if let Some((source, file, destination)) = remote_open {
app.open_remote_link(source, file, destination);
}
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 79464624c..3ce3f76df 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -2169,6 +2169,7 @@ impl PdfCraftApp {
/// Switches workspace because the user chose to (mode bar, Read mode command). Entering Read
/// mode closes the right panel, as Acrobat's Read mode hides its panes, and leaving it reopens
/// that panel. The rail stays in Read mode, and its buttons open panels there too (#932).
+ /// Read mode hides the quick toolbar, so entering it also puts the current tool down.
pub(crate) fn switch_mode(&mut self, mode: Mode, select_tools: bool) {
let was_read = self.mode == Mode::Read;
if select_tools {
@@ -2178,6 +2179,7 @@ impl PdfCraftApp {
}
if mode == Mode::Read && !was_read {
self.right_before_read = self.right.take();
+ self.quick_tool = QuickTool::Select;
} else if mode != Mode::Read && was_read {
let before = self.right_before_read.take();
if self.right.is_none() {
diff --git a/crates/ui-egui/tests/ui.rs b/crates/ui-egui/tests/ui.rs
index 1b6276d7c..cc52b01a0 100644
--- a/crates/ui-egui/tests/ui.rs
+++ b/crates/ui-egui/tests/ui.rs
@@ -246,6 +246,24 @@ fn read_mode_closes_the_panes_and_leaving_it_brings_them_back() {
assert_eq!(h.state().right, Some(RightPanel::Pages));
}
+/// Read mode hides the quick toolbar too, and puts down the tool that was in use (#2646).
+#[test]
+fn read_mode_hides_the_quick_toolbar() {
+ use pdfcraft_ui_egui::{Mode, QuickTool};
+ let mut h = harness(|app| app.open_bytes("fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens"));
+ h.get_by_label("Hand (H)").click();
+ h.run_steps(2);
+ assert_eq!(h.state().quick_tool, QuickTool::Hand);
+ h.get_by_label("Read").click();
+ h.run_steps(3);
+ assert!(h.query_by_label("Select (V)").is_none(), "no quick toolbar in Read mode");
+ assert_eq!(h.state().quick_tool, QuickTool::Select);
+ h.state_mut().run_command("view.read_mode");
+ h.run_steps(3);
+ assert_eq!(h.state().mode, Mode::AllTools);
+ h.get_by_label("Select (V)");
+}
+
/// A pane closed in Read mode stays closed on the way out: leaving Read mode doesn't bring back the
/// pane saved on the way in, and closing Comments keeps its close preference.
#[test]