From 60bfaa604879148b329d73af654302875769b58a Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 20 Nov 2026 02:10:53 -0500 Subject: [PATCH] pipe editing-3: fixes for editing (10 tests) --- crates/ui-egui/src/dialogs/page_props.rs | 11 ++++++-- crates/ui-egui/src/editing/close.rs | 3 +- crates/ui-egui/tests/it/editing.rs | 35 ++++++++++++++++++------ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/crates/ui-egui/src/dialogs/page_props.rs b/crates/ui-egui/src/dialogs/page_props.rs index 44592e7baf..2f43d7b410 100644 --- a/crates/ui-egui/src/dialogs/page_props.rs +++ b/crates/ui-egui/src/dialogs/page_props.rs @@ -1,6 +1,7 @@ //! Page Properties ▸ Tab Order for the pages the dialog opened on: Use Row Order, Use Column Order, Use Document //! Structure and Unspecified, as a hosted dialog with one radio row. +use craft::ui::contract::Bind; use craft::ui::dialog::{DialogResult, dialog_id}; use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog, Param, ParamDialog, ParamKind}; use pdfcraft_engine::{Edit, TabOrder}; @@ -37,8 +38,14 @@ impl PdfCraftApp { (order_id(TabOrder::Annotations).to_string(), tl!("Unspecified").into()), ]; let default = draft.before.map(|o| order_id(o).to_string()); - let params = vec![Param::new(ORDER, tl!("Tab Order"), ParamKind::radio(options, default))]; - let dialog = HostedParamDialog::new(ctx, KEY, DialogFields::new(), move |_| ParamDialog::new(KEY, tl!("Page Properties"), params.clone())); + let params = vec![Param::new(ORDER, tl!("Tab Order"), ParamKind::radio(options, default.clone()))]; + let mut fields = DialogFields::new(); + // An empty id represents mixed orders; leaving the field absent picks the first radio. + fields.set(ORDER, default.unwrap_or_default()); + let dialog = HostedParamDialog::new(ctx, KEY, fields, move |fields| { + let chosen = fields.text(ORDER).and_then(order_of).is_some(); + ParamDialog::new(KEY, tl!("Page Properties"), params.clone()).ok_enabled(chosen).values(Bind::bound(fields)) + }); self.dialogs.open(dialog); self.page_props_draft = Some(draft); } diff --git a/crates/ui-egui/src/editing/close.rs b/crates/ui-egui/src/editing/close.rs index 9a9f09238a..987309d1a3 100644 --- a/crates/ui-egui/src/editing/close.rs +++ b/crates/ui-egui/src/editing/close.rs @@ -262,7 +262,8 @@ impl PdfCraftApp { } let name = self.session.get(doc).map(|d| d.name.clone()).unwrap_or_default(); let remaining = self.close_guard.as_ref().map_or(1, |g| g.remaining()); - self.close_guard_dialog = Some(self.dialogs.open(UnsavedChangesDialog::new(scope, name).remaining(remaining))); + let shown = crate::dialogs::shorten_middle(&name, 80); + self.close_guard_dialog = Some(self.dialogs.open(UnsavedChangesDialog::new(scope, shown).remaining(remaining))); } /// Saves `doc`, then lets the guard go on. The save may finish on a later frame (the user diff --git a/crates/ui-egui/tests/it/editing.rs b/crates/ui-egui/tests/it/editing.rs index afdd85a546..fa60aff792 100644 --- a/crates/ui-egui/tests/it/editing.rs +++ b/crates/ui-egui/tests/it/editing.rs @@ -3500,25 +3500,41 @@ fn switching_from_a_narrow_editor_keeps_one_frame_and_a_wide_heading_on_one_line h.run_steps(2); } } + // Unchanged text is painted by the page; an edit exposes the editor's layout. + h.state_mut().views[0].session.line_editor.as_mut().unwrap().text.push('!'); + h.run_steps(3); let heading = h .output() .shapes .iter() .find_map(|shape| match &shape.shape { - egui::Shape::Text(text) if text.galley.text() == "Editable PDF heading" => Some(&text.galley), + egui::Shape::Text(text) if text.galley.text() == "Editable PDF heading!" => { + Some((text.galley.rect.translate(text.pos.to_vec2()), &text.galley)) + } _ => None, }) .expect("the heading editor is painted"); - assert_eq!(heading.rows.len(), 1, "opening a wider block must not reuse the previous editor's narrow width"); + assert_eq!(heading.1.rows.len(), 1, "opening a wider block must not reuse the previous editor's narrow width"); + let frame_stroke = h + .output() + .shapes + .iter() + .rev() + .find_map(|shape| match &shape.shape { + egui::Shape::Path(path) if path.closed && egui::Rect::from_points(&path.points).contains(heading.0.min) => Some(path.stroke.clone()), + _ => None, + }) + .expect("the heading has an outline"); let frames = h .output() .shapes .iter() - .filter(|shape| { - matches!(&shape.shape, - egui::Shape::Rect(rect) if rect.stroke.color == egui::Color32::from_rgb(0x14, 0x73, 0xE6) - && rect.rect.width() > 100.0 && page.contains(rect.rect.center()) - ) + .filter_map(|shape| match &shape.shape { + egui::Shape::Path(path) if path.closed && path.stroke == frame_stroke => { + let rect = egui::Rect::from_points(&path.points); + (rect.width() > 100.0 && page.contains(rect.center())).then_some(rect) + } + _ => None, }) .count(); assert_eq!(frames, 1, "the active block has only the editor frame"); @@ -6462,7 +6478,10 @@ fn one_editor_contains_mixed_styles_and_visual_rows() { .shapes .iter() .find_map(|s| match &s.shape { - egui::Shape::Rect(r) if r.stroke.color == egui::Color32::from_rgb(0x14, 0x73, 0xE6) && r.rect.width() > 50.0 => Some(r.rect), + egui::Shape::Path(path) if path.closed => { + let rect = egui::Rect::from_points(&path.points); + (rect.width() > 50.0 && rect.contains(visible.min)).then_some(rect) + } _ => None, }) .unwrap();