PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
M12: full screen survives a reload and starts after the document's own initial view (#379)
mtlcl4103ed0dff80793
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex eb539d985..51112a814 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -859,9 +859,9 @@ impl DocView {}/// The document was replaced by a newer version of its file (#431). The reader's place- /// stays: zoom, layout, rotation, page, scroll, view history and the find bar, the snapshot- /// marker and its pending close, and the page images on screen until their replacements- /// are drawn, so nothing flashes. Everything that pointed into the old version (a selected+ /// stays: zoom, layout, rotation, page, scroll, full screen, view history and the find bar,+ /// the snapshot marker and its pending close, and the page images on screen until their+ /// replacements are drawn, so nothing flashes. Everything that pointed into the old version (a selected/// comment, a field being typed in, text being edited, a drag, page selection) starts/// afresh, so no stale index reaches the new one.pub fn document_replaced(&mut self, info: &DocInfo) {@@ -881,6 +881,8 @@ impl DocView {fresh.snapshot = self.snapshot.clone();fresh.close_requested = self.close_requested;fresh.cover = self.cover;+ // Still presenting, with the display to go back to on leaving.+ fresh.presentation = self.presentation.take();fresh.back = std::mem::take(&mut self.back);fresh.forward = std::mem::take(&mut self.forward);fresh.find = self.find.take();diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 40be115df..cc7a486fc 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1338,15 +1338,18 @@ impl PdfCraftApp {};}let initial = doc.initial_view();- let mut view = DocView::new(id, &doc.info, self.view_defaults);- if self.full_screen {- view.enter_presentation();- }+ let view = DocView::new(id, &doc.info, self.view_defaults);self.views.push(view);if activate {self.active = Some(self.views.len() - 1);}self.apply_initial_view(self.views.len() - 1, &initial);+ // After the document's own initial view, so leaving full screen comes back to it.+ if self.full_screen+ && let Some(view) = self.views.last_mut()+ {+ view.enter_presentation();+ }// Full screen is asked for, never taken: a document can't put the app in full screen on// its own (the prompt is `dialogs::full_screen_prompt`).if activate && initial.full_screen {diff --git a/crates/ui-egui/tests/view.rs b/crates/ui-egui/tests/view.rsindex f3d5717db..74ea5965b 100644--- a/crates/ui-egui/tests/view.rs+++ b/crates/ui-egui/tests/view.rs@@ -1702,6 +1702,41 @@ fn full_screen_shows_one_fitted_page_and_clicks_turn_it() {assert!(h.query_by_label("Select (V)").is_some(), "the quick tools are back");}+/// #2070 review: full screen survives the file being reloaded (Esc still brings the display from+/// before back), and a document opened in full screen takes its own initial view first, so Esc+/// comes back to that and full screen stays one spread at a time.+#[test]+fn full_screen_survives_a_reload_and_keeps_a_new_documents_own_view() {+ use pdfcraft_ui_egui::canvas::{Fit, PageLayout};+ let mut h = harness(&[("layout", "continuous"), ("zoom", "50")]);+ h.run_steps(4);+ h.key_press_modifiers(Modifiers::COMMAND, Key::L);+ h.run_steps(6);+ {+ let app = h.state_mut();+ let info = app.session.get(app.views[0].id).unwrap().info.clone();+ app.views[0].document_replaced(&info);+ }+ h.run_steps(4);+ assert!(h.state().views[0].presenting(), "still presenting after the reload");+ h.key_press(Key::Escape);+ h.run_steps(4);+ let v = &h.state().views[0];+ assert!(v.continuous() && v.fit == Fit::None && (v.zoom - 0.5).abs() < 1e-3, "the display from before comes back");++ h.key_press_modifiers(Modifiers::COMMAND, Key::L);+ h.run_steps(6);+ let two_columns = String::from_utf8_lossy(PAGES).replace("/Type /Catalog /Pages 2 0 R", "/Type /Catalog /Pages 2 0 R /PageLayout /TwoColumnLeft");+ h.state_mut().open_bytes("two.pdf", None, two_columns.into_bytes()).expect("opens");+ h.run_steps(6);+ let v = h.state().views.last().unwrap();+ assert!(v.presenting() && v.layout == PageLayout::TwoUp && !v.continuous(), "one spread at a time");+ h.key_press(Key::Escape);+ h.run_steps(4);+ let v = h.state().views.last().unwrap();+ assert!(v.layout == PageLayout::TwoUp && v.continuous(), "the document's own two-column view comes back");+}+/// Two-page view stays a spread in full screen (#1353): both pages of the spread, fitted, and/// → turns the spread.#[test]