From eb6fda20cb56d39a32cfb4f766eafcf26b7c60cf Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 1 Dec 2026 09:50:16 -0800 Subject: [PATCH] Import PDF: name Crop To only when it differs from the box it started on A keyboard preview canceled with Escape restores the starting box, so it no longer counts as a pick. --- crates/ui-egui/src/dialogs/import_pdf.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/dialogs/import_pdf.rs b/crates/ui-egui/src/dialogs/import_pdf.rs index fd141eb74b..5121f37c16 100644 --- a/crates/ui-egui/src/dialogs/import_pdf.rs +++ b/crates/ui-egui/src/dialogs/import_pdf.rs @@ -10,9 +10,9 @@ //! for All, off for a range; picking the other of All and Range sets it back to `null`; `linksOn` //! is the effective flag, `__linkable` is false for a file `linkPages` does not take, such as one //! over its size limit), `cropTo` (when opening, it starts on `trim` for a file with editing data, -//! else `crop`; OK names the box only when it was picked, so a file with the starting box opens -//! as it does without the dialog), `textAs` (`text` | `outlines`; it starts from the `pdfTextAs` -//! preference for a PDF (`__pdf`; Editable for a `.ai` or `.ait` file), or from the `textAs` a place +//! else `crop`; OK names the box only when it differs from the box it started on, so a file with +//! the starting box opens as it does without the dialog), `textAs` (`text` | `outlines`; it starts +//! from the `pdfTextAs` preference for a PDF (`__pdf`; Editable for a `.ai` or `.ait` file), or from the `textAs` a place //! gives (`__textAsGiven`), and OK keeps a PDF's choice there; a linked place shows the file's own //! text, so placing linked leaves it as it is, and Outlines clears Import PDF Pages as Links) and //! `password`. `__locked` is set until the password is accepted: OK then unlocks the file, and with @@ -148,9 +148,9 @@ struct State { pages: Vec, link_pages: Option, crop: CropTo, - /// Whether Crop To was picked. Opening, a box left as it starts ([`opening_crop`]) is not - /// named, so a file with editing data opens on its trim boxes, as it opens without the dialog. - crop_chosen: bool, + /// The box Crop To started on ([`opening_crop`] when opening). OK names the box only when + /// it differs from this box. + start_crop: CropTo, text_as: TextAs, pdf: bool, password: String, @@ -220,8 +220,9 @@ impl State { let opened = vectorcraft_pdf::open_pdf(&self.file.bytes, self.password().as_deref()).map_err(|e| e.to_string())?; self.locked = false; self.page_count = opened.page_count(); - if !self.crop_chosen && self.place.is_none() { + if self.crop == self.start_crop && self.place.is_none() { self.crop = opening_crop(Some(&opened)); + self.start_crop = self.crop; } Ok(self.page_count > 1 && !self.password_only) } @@ -278,7 +279,6 @@ impl State { let text = text()?; let i = CropTo::IDS.iter().position(|id| *id == text).ok_or("cropTo is not a crop box")?; self.crop = CropTo::ALL.get(i).copied().unwrap_or_default(); - self.crop_chosen = true; } "textAs" => { let id = text()?; @@ -468,9 +468,7 @@ fn pages_body(ui: &mut egui::Ui, s: &mut State, preview: Option<&(Revision, Arc< }); Stack::new().show(ui, |ui, _| { let crops: Vec> = CropTo::ALL.iter().zip(CropTo::LABELS).map(|(crop, label)| Entry::new(*crop, *label)).collect(); - let before = s.crop; Field::new(tl!("Crop To")).show(ui, |ui, _| Select::new(tl!("Crop To"), Bind::bound(&mut s.crop), &crops).show(ui)); - s.crop_chosen |= s.crop != before; let linked = s.places_linked(); let texts = [Entry::new(TextAs::Text, tl!("Editable")), Entry::new(TextAs::Outlines, tl!("Outlines"))]; Field::new(tl!("Text")).show(ui, |ui, _| Select::new(tl!("Text"), Bind::bound(&mut s.text_as), &texts).enabled(!linked).show(ui)); @@ -563,7 +561,7 @@ fn offer_with(app: &mut VectorcraftApp, name: &str, bytes: &[u8], path: Option Result<(), String> { let mut p = json!({"password": s.password(), "textAs": s.text_as.id()}); // A box left as it starts ([`opening_crop`]) is not named: a file with editing data then // opens on its trim boxes, from its editing layers where it can, as without the dialog. - if s.crop_chosen { + if s.crop != s.start_crop { p["cropTo"] = json!(s.crop.id()); } // An empty range under Range opens every page.