From e90b3bec561d2e28869985a4ba0ff13fa94aba92 Mon Sep 17 00:00:00 2001 From: Hartmut Noerenberg Date: Sat, 14 Nov 2026 11:59:41 +0100 Subject: [PATCH 01/10] feat(type-tool): Alt+drag opens the Paragraph Text Size dialog --- crates/ui-egui/src/canvas/gesture.rs | 4 +- crates/ui-egui/src/dialogs.rs | 4 + .../src/dialogs/paragraph_text_size.rs | 87 +++++++++++ .../src/dialogs/paragraph_text_size/tests.rs | 142 +++++++++++++++++ crates/ui-egui/src/lib.rs | 1 + crates/ui-egui/src/tools/type_tool.rs | 2 +- .../src/tools/type_tool/canvas_tests.rs | 6 +- .../src/tools/type_tool/commit_tests.rs | 2 +- .../type_tool/ctrl_period_cancel_tests.rs | 2 +- crates/ui-egui/src/tools/type_tool/editing.rs | 10 +- .../src/tools/type_tool/font_commit_tests.rs | 4 +- .../ui-egui/src/tools/type_tool/ime_tests.rs | 4 +- .../type_tool/locked_layer_alert_tests.rs | 4 +- .../src/tools/type_tool/mask_escape_tests.rs | 2 +- crates/ui-egui/src/tools/type_tool/pointer.rs | 146 +++++++++++------- crates/ui-egui/src/tools/type_tool/tests.rs | 46 +++--- .../type_tool/vertical_align_buttons_tests.rs | 2 +- .../vertical_mask_align_buttons_tests.rs | 2 +- 18 files changed, 367 insertions(+), 103 deletions(-) create mode 100644 crates/ui-egui/src/dialogs/paragraph_text_size.rs create mode 100644 crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs diff --git a/crates/ui-egui/src/canvas/gesture.rs b/crates/ui-egui/src/canvas/gesture.rs index 155ae25ac88..72ae018ec5c 100644 --- a/crates/ui-egui/src/canvas/gesture.rs +++ b/crates/ui-egui/src/canvas/gesture.rs @@ -120,7 +120,9 @@ fn finish(app: &mut PhotocraftApp, mut d: Drag, click: Option) { || crate::shape_dialog::open(app, t, d.start).is_some()) => {} t if crate::vector_ui::is_shape_tool(t) => crate::vector_ui::finish_shape(app, t, d.start, [end[0], end[1]], d.live), Tool::PathSelection => crate::vector_ui::path_selection_finish(app, d.start, [end[0], end[1]]), - Tool::Type | Tool::VerticalType | Tool::HorizontalTypeMask | Tool::VerticalTypeMask => crate::type_tool::pointer_up(app, d.start, [end[0], end[1]]), + Tool::Type | Tool::VerticalType | Tool::HorizontalTypeMask | Tool::VerticalTypeMask => { + crate::type_tool::pointer_up(app, d.start, [end[0], end[1]], d.modifiers) + } Tool::Brush | Tool::Pencil | Tool::Eraser => commit_brush_stroke(app, &d), Tool::RectMarquee | Tool::EllipseMarquee => { // Exactly what the drag showed (`marquee_preview_px`); a click deselects. diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index e22931d1900..35975645d7a 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -367,6 +367,7 @@ fn command_body_more(app: &mut PhotocraftApp, ui: &mut egui::Ui, d: &Dialog, fie } _ if fields.contains_key("__filter") => filter_body(app, ui, d, fields, id), _ if crate::new_guide_ui::owns(fields) => crate::new_guide_ui::body(ui, fields), + _ if crate::paragraph_text_size::owns(fields) => crate::paragraph_text_size::body(ui, fields), _ if crate::equalize_ui::owns(fields) => crate::equalize_ui::body(ui, fields), _ if fields.contains_key("__form") => { if fields.get("__command").and_then(Value::as_str) == Some("file.fileInfo") { @@ -925,6 +926,7 @@ const ROUTES: &[fn(&Fields) -> bool] = &[ crate::variables_ui::owns, crate::file_ui::owns, crate::new_guide_ui::owns, + crate::paragraph_text_size::owns, crate::equalize_ui::owns, crate::color_picker_ui::owns, crate::color_range_ui::owns, @@ -1157,6 +1159,7 @@ fn confirm_command_more(app: &mut PhotocraftApp, d: Dialog) -> Result live_shape_prompt::confirm(app, &d.fields), _ if crate::file_ui::owns(&d.fields) => crate::file_ui::confirm(app, &d.fields), _ if crate::new_guide_ui::owns(&d.fields) => crate::new_guide_ui::confirm(app, &d.fields), + _ if crate::paragraph_text_size::owns(&d.fields) => crate::paragraph_text_size::confirm(app, &d.fields), _ if crate::color_picker_ui::owns(&d.fields) => { // OK sets the target as it was before the live preview showed the colour in it. crate::color_picker_ui::live_preview::end(app, d.id); @@ -1337,6 +1340,7 @@ pub mod new_guide_ui; pub mod new_layer_ui; pub mod open_prompt; pub mod palette; +pub mod paragraph_text_size; pub(crate) mod pattern_fill_ui; pub mod preset_group_prompt; pub mod rasterize_prompt; diff --git a/crates/ui-egui/src/dialogs/paragraph_text_size.rs b/crates/ui-egui/src/dialogs/paragraph_text_size.rs new file mode 100644 index 00000000000..d94fe396f11 --- /dev/null +++ b/crates/ui-egui/src/dialogs/paragraph_text_size.rs @@ -0,0 +1,87 @@ +//! Paragraph Text Size: Alt+drag with the Type tool sizes the new paragraph box in a modal dialog +//! instead of committing the drag (#12044). Width and Height open in document pixels with the size +//! that was dragged, decimals kept (a ~100 px drag prefills 99.5), and the box keeps its top-left +//! where the drag started. OK runs the same `type.create` a plain drag does, so the placeholder +//! text lands selected exactly as it does there; Cancel closes the dialog and creates nothing. +//! +//! Only what the ticket measured is here. No field rule was measured — no unit menu, no minimum, +//! no maximum — so the number goes to `type.create` as typed and the engine refuses a box it +//! cannot make. A drag upwards or to the left of its start keeps today's rule (the box is the +//! rectangle between the two points), and Cancel beyond closing the dialog is not specified. +//! +//! The dialog is an ordinary one in the UI state, so `ui.inspect`, `ui.dialog.confirm` and +//! `ui.dialog.cancel` drive it, and its two fields live in the dialog's field map. + +use serde_json::{Map, Value, json}; + +use crate::PhotocraftApp; +use crate::state::DialogKind; + +const MARK: &str = "__paragraphTextSize"; +const COMMAND: &str = "type.create"; +/// The top-left the box was dragged from, in document pixels: OK puts the box there, whatever its +/// size becomes in the dialog. +const AT: &str = "__at"; + +/// Identify the Paragraph Text Size dialog fields. +pub fn owns(fields: &Map) -> bool { + fields.contains_key(MARK) +} + +/// Open the dialog on the box an Alt+drag drew: top-left `(x, y)`, size `w` × `h`, in document +/// pixels and exactly as dragged (the fields keep the decimals). +pub fn open(app: &mut PhotocraftApp, at: [f64; 2], w: f64, h: f64) -> u64 { + let mut f = Map::new(); + f.insert(MARK.into(), json!(true)); + f.insert("__command".into(), json!(COMMAND)); + f.insert("__label".into(), json!("Paragraph Text Size")); + f.insert(AT.into(), json!([at[0], at[1]])); + f.insert("width".into(), json!(w)); + f.insert("height".into(), json!(h)); + app.ui.open_dialog(DialogKind::Command, f) +} + +/// `f[key]` as a document-pixel length. +fn px(f: &Map, key: &str) -> Option { + f.get(key).and_then(Value::as_f64).filter(|v| v.is_finite()) +} + +/// The two rows, Width and Height, in document pixels. +pub fn body(ui: &mut egui::Ui, f: &mut Map) { + egui::Grid::new("paragraph-text-size-dialog").num_columns(2).spacing([12.0, 8.0]).show(ui, |ui| { + for (key, label) in [("width", tl!("Width")), ("height", tl!("Height"))] { + ui.label(label); + let mut px = px_or(f, key); + // One decimal shows a dragged half pixel (99.5) as such; no range is measured, so the + // field takes the number and `type.create` refuses a box it cannot make. + let field = crate::widgets::value_field_prec(ui, &mut px, -1.0e9..=1.0e9, "px", 110.0, 1).accessible_name(label); + if field.changed() { + f.insert(key.into(), json!(f64::from(px))); + } + ui.end_row(); + } + }); +} + +/// The field's current length, as the widget sees it (a length the dialog never held shows 0). +fn px_or(f: &Map, key: &str) -> f32 { + px(f, key).map_or(0.0, |v| v as f32) +} + +/// OK: create the paragraph text the dialog sized, the same layer a plain drag of the same box +/// would have made. +pub fn confirm(app: &mut PhotocraftApp, f: &Map) -> Result { + let at = f.get(AT).and_then(Value::as_array); + let (Some(x), Some(y)) = (at.as_ref().and_then(|a| a.first()).and_then(Value::as_f64), at.as_ref().and_then(|a| a.get(1)).and_then(Value::as_f64)) else { + return Err("the Paragraph Text Size dialog has no position".into()); + }; + let (Some(w), Some(h)) = (px(f, "width"), px(f, "height")) else { + return Err("the Paragraph Text Size dialog has no size".into()); + }; + let mut p = crate::type_tool::create_params(app); + p["box"] = json!([x, y, w, h]); + crate::type_tool::create_layer(app, p, None).map(|layer| json!({"layer": layer})) +} + +#[cfg(test)] +mod tests; diff --git a/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs b/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs new file mode 100644 index 00000000000..594b28d8576 --- /dev/null +++ b/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs @@ -0,0 +1,142 @@ +//! Alt+drag with the Type tool and the Paragraph Text Size dialog it opens (#12044): the dialog is +//! measured (prefilled with the dragged size, decimals kept, OK creates the box at the drag start, +//! Cancel creates nothing), and the two unmeasured neighbours of that route are checked to keep +//! today's behaviour: a plain drag still makes the box directly, and Alt+click is still point text. + +use egui::Modifiers; +use photocraft_doc::LayerContent; +use serde_json::{Value, json}; + +use super::*; +use crate::canvas::{Drag, finish_gesture}; +use crate::state::Tool; +use crate::type_tool::PLACEHOLDER; + +/// A 400 × 200 document with the Type tool ready. +fn app() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 200})).unwrap(); + app.sync_views(); + app.ui.tool = Tool::Type; + app +} + +/// Release a Type-tool gesture pressed at `start` and released at `end` with `mods` held, the way +/// the canvas does (`canvas::gesture` hands the gesture's modifiers to the Type tool). +fn drag(app: &mut PhotocraftApp, start: [f64; 2], end: [f64; 2], mods: Modifiers) { + let d = Drag::new(Tool::Type, start, vec![[start[0], start[1], 1.0], [end[0], end[1], 1.0]], mods, false); + finish_gesture(app, d); +} + +fn layers(app: &PhotocraftApp) -> usize { + app.session.active().unwrap().doc.layers.len() +} + +/// The dialog the gesture opened, and only it. +fn only_dialog(app: &PhotocraftApp) -> u64 { + assert_eq!(app.ui.dialogs.len(), 1, "the Alt+drag opens one dialog"); + let d = &app.ui.dialogs[0]; + assert!(owns(&d.fields), "it is the Paragraph Text Size dialog"); + d.id +} + +/// Set dialog fields without confirming them. +fn set(app: &mut PhotocraftApp, id: u64, fields: Value) { + let d = app.ui.dialog_mut(id).unwrap(); + for (k, v) in fields.as_object().unwrap() { + d.fields.insert(k.clone(), v.clone()); + } +} + +fn text(app: &PhotocraftApp, id: u64) -> photocraft_doc::TextLayer { + let st = app.session.active().unwrap(); + let layer = st.doc.layer(photocraft_doc::LayerId(id)).unwrap(); + let LayerContent::Text(t) = &layer.content else { panic!("not a type layer") }; + t.clone() +} + +/// The paragraph box of `id` in document pixels: its top-left through the layer transform, then its +/// width and height. +fn box_rect(app: &PhotocraftApp, id: u64) -> [f64; 4] { + let t = text(app, id); + let photocraft_doc::text::TextShape::Box { x, y, width, height } = t.shape else { panic!("not paragraph text") }; + [t.transform.m[4] + f64::from(x), t.transform.m[5] + f64::from(y), f64::from(width), f64::from(height)] +} + +/// #12044: Alt+drag opens the modal dialog instead of creating the text, prefilled with the size +/// that was dragged — including its decimals. +#[test] +fn alt_drag_opens_the_dialog_prefilled_with_the_dragged_size() { + let mut app = app(); + let before = layers(&app); + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT); + let id = only_dialog(&app); + assert_eq!(crate::dialogs::title(&app.ui.dialogs[0]), "Paragraph Text Size"); + let f = &app.ui.dialog_mut(id).unwrap().fields; + assert_eq!((f["width"].as_f64(), f["height"].as_f64()), (Some(99.5), Some(50.0)), "the dragged size, decimals kept"); + assert_eq!(f["__command"].as_str(), Some("type.create")); + assert_eq!(layers(&app), before, "the drag itself creates nothing"); + assert!(app.ui.text_edit.is_none(), "and starts no edit session"); +} + +/// OK creates the paragraph layer with the box the dialog holds, top-left at the drag's start, and +/// the placeholder selected — as a plain drag of that box does. +#[test] +fn confirming_creates_the_paragraph_box_at_the_drag_start() { + let mut app = app(); + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT); + let d = only_dialog(&app); + set(&mut app, d, json!({"width": 250.0, "height": 120.0})); + let r = crate::dialogs::confirm(&mut app, d).unwrap(); + let id = r["layer"].as_u64().unwrap(); + assert!(app.ui.dialogs.is_empty(), "OK closes the dialog"); + assert_eq!(box_rect(&app, id), [10.0, 10.0, 250.0, 120.0], "the dialog's box at the drag's start"); + let ed = app.ui.text_edit.as_ref().expect("OK starts the edit session, as the drag does"); + assert_eq!((ed.layer, ed.anchor, ed.caret), (id, 0, PLACEHOLDER.chars().count()), "placeholder text, all of it selected"); + assert_eq!(text(&app, id).text, PLACEHOLDER); +} + +/// Cancel closes the dialog and creates nothing: no layer, no edit session. +#[test] +fn cancelling_creates_nothing() { + use egui_kittest::{Harness, kittest::Queryable}; + + let app = app(); + // The harness first, so its fonts are installed before the dialog is drawn. + let mut h = Harness::builder().with_size(egui::vec2(900.0, 700.0)).build_ui_state(|ui, app| crate::dialogs::show(app, ui.ctx()), app); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ProMedium); + h.run_steps(3); + let before = layers(h.state()); + drag(h.state_mut(), [10.0, 10.0], [109.5, 60.0], Modifiers::ALT); + h.run_steps(3); + only_dialog(h.state()); + // The dialog is up with the fields the prefill test pinned; what this test owns is that the + // rendered Cancel button closes it and creates nothing. + h.get_by_label("Cancel").click(); + h.run_steps(3); + assert!(h.state().ui.dialogs.is_empty(), "Cancel closes the dialog"); + assert_eq!(layers(h.state()), before, "Cancel creates nothing"); + assert!(h.state().ui.text_edit.is_none()); +} + +/// Not measured by the ticket, so unchanged: a drag without Alt still commits the box directly. +#[test] +fn a_plain_drag_still_makes_the_box_directly() { + let mut app = app(); + drag(&mut app, [10.0, 10.0], [110.0, 60.0], Modifiers::NONE); + assert!(!app.ui.dialogs.iter().any(|d| owns(&d.fields)), "a plain drag opens no dialog"); + let ed = app.ui.text_edit.as_ref().expect("the drag creates the text at once"); + assert_eq!(box_rect(&app, ed.layer), [10.0, 10.0, 100.0, 50.0]); +} + +/// Not measured by the ticket, so unchanged: Alt+click (no drag) stays point text. +#[test] +fn an_alt_click_is_still_point_text() { + let mut app = app(); + drag(&mut app, [50.0, 100.0], [50.0, 100.0], Modifiers::ALT); + assert!(!app.ui.dialogs.iter().any(|d| owns(&d.fields)), "a click opens no dialog"); + let ed = app.ui.text_edit.as_ref().expect("the click creates point text"); + let t = text(&app, ed.layer); + assert!(matches!(t.shape, photocraft_doc::text::TextShape::Point), "point text"); + assert_eq!([t.transform.m[4], t.transform.m[5]], [50.0, 100.0]); +} diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 7928bf442c0..1f1db53d3d3 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -172,6 +172,7 @@ pub use dialogs::new_guide_ui; pub use dialogs::new_layer_ui; pub use dialogs::open_prompt; pub use dialogs::palette; +pub use dialogs::paragraph_text_size; pub(crate) use dialogs::pattern_fill_ui; pub use dialogs::preset_group_prompt; pub use dialogs::rasterize_prompt; diff --git a/crates/ui-egui/src/tools/type_tool.rs b/crates/ui-egui/src/tools/type_tool.rs index 636c0f3e75e..0f537351dc2 100644 --- a/crates/ui-egui/src/tools/type_tool.rs +++ b/crates/ui-egui/src/tools/type_tool.rs @@ -76,7 +76,7 @@ pub(crate) use panel::{OPENTYPE_BUTTONS, toggle_opentype}; pub use panel::{character_panel, type_properties}; #[cfg(test)] use pointer::{MIN_BOX, handle_sides, word_boundary}; -pub(crate) use pointer::{PathClick, box_handle_at, hover_path_target, inside_box}; +pub(crate) use pointer::{PathClick, box_handle_at, create_layer, create_params, hover_path_target, inside_box}; #[cfg(test)] pub(crate) use pointer::{box_shape, click_selection, next_click_count, path_target}; pub use pointer::{multi_click, pointer_down, pointer_move, pointer_up}; diff --git a/crates/ui-egui/src/tools/type_tool/canvas_tests.rs b/crates/ui-egui/src/tools/type_tool/canvas_tests.rs index 96c0551955f..1ff9638cdfc 100644 --- a/crates/ui-egui/src/tools/type_tool/canvas_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/canvas_tests.rs @@ -186,7 +186,7 @@ mod panel_defaults { app.ui.tool = tool; app.session.tools.foreground = [0.2, 0.4, 0.6, 1.0]; let revision = app.session.active().unwrap().revision; - super::super::pointer_up(&mut app, [100.0, 100.0], if paragraph { [500.0, 400.0] } else { [100.0, 100.0] }); + super::super::pointer_up(&mut app, [100.0, 100.0], if paragraph { [500.0, 400.0] } else { [100.0, 100.0] }, egui::Modifiers::NONE); let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer); let t = text(&app, id); let c = &t.char_runs()[0].style; @@ -305,7 +305,7 @@ mod panel_defaults { crate::dialogs::confirm(&mut app, dialog).unwrap(); assert_eq!(super::super::default_styles(&app).0.color.to_rgba8(), [51, 102, 153, 255]); assert_eq!(app.session.active().unwrap().revision, revision); - super::super::pointer_up(&mut app, [100.0, 100.0], [100.0, 100.0]); + super::super::pointer_up(&mut app, [100.0, 100.0], [100.0, 100.0], egui::Modifiers::NONE); let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer); assert_eq!(text(&app, id).char_runs()[0].style.color.to_rgba8(), [51, 102, 153, 255]); } @@ -2087,7 +2087,7 @@ mod multi_layer_formatting { assert_eq!(text(h.state(), *id).paragraph_runs()[0].style.direction, TextDirection::Rtl); } assert_eq!(text(h.state(), ids[2]).paragraph_runs()[0].style.direction, TextDirection::Auto); - super::super::pointer_up(h.state_mut(), [40.0, 60.0], [40.0, 60.0]); + super::super::pointer_up(h.state_mut(), [40.0, 60.0], [40.0, 60.0], egui::Modifiers::NONE); let id = h.state().session.active().unwrap().active_layer.unwrap(); assert!(!ids.contains(&id), "a new type layer"); assert_eq!(text(h.state(), id).paragraph_runs()[0].style.direction, TextDirection::Rtl, "new type starts right to left"); diff --git a/crates/ui-egui/src/tools/type_tool/commit_tests.rs b/crates/ui-egui/src/tools/type_tool/commit_tests.rs index e25fc339778..5353c4c6e20 100644 --- a/crates/ui-egui/src/tools/type_tool/commit_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/commit_tests.rs @@ -25,7 +25,7 @@ fn text_of(app: &PhotocraftApp, doc: usize, id: LayerId) -> Option { /// Start a new type layer with a click and type `s` into it, as the canvas does. fn type_new(app: &mut PhotocraftApp, s: &str) -> LayerId { - super::pointer_up(app, [50.0, 100.0], [50.0, 100.0]); + super::pointer_up(app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); super::insert(app, s); LayerId(app.ui.text_edit.as_ref().unwrap().layer) } diff --git a/crates/ui-egui/src/tools/type_tool/ctrl_period_cancel_tests.rs b/crates/ui-egui/src/tools/type_tool/ctrl_period_cancel_tests.rs index 73948ebf8c0..e4e76d17d0f 100644 --- a/crates/ui-egui/src/tools/type_tool/ctrl_period_cancel_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/ctrl_period_cancel_tests.rs @@ -24,7 +24,7 @@ fn new_app(tool: Tool) -> PhotocraftApp { /// Start new text with a click and type `s`, as the canvas does. fn type_new(app: &mut PhotocraftApp, s: &str) { - super::pointer_up(app, [50.0, 100.0], [50.0, 100.0]); + super::pointer_up(app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); super::insert(app, s); } diff --git a/crates/ui-egui/src/tools/type_tool/editing.rs b/crates/ui-egui/src/tools/type_tool/editing.rs index 33d80b8bdba..17f74177cd0 100644 --- a/crates/ui-egui/src/tools/type_tool/editing.rs +++ b/crates/ui-egui/src/tools/type_tool/editing.rs @@ -630,7 +630,7 @@ mod indexed_commit_tests { fn committing_in_indexed_color_or_bitmap_leaves_the_glyphs_selected() { // The bounds the same text covers where it does become a layer. let mut rgb = app("rgb"); - pointer_up(&mut rgb, [80.0, 120.0], [80.0, 120.0]); + pointer_up(&mut rgb, [80.0, 120.0], [80.0, 120.0], egui::Modifiers::NONE); insert(&mut rgb, "Hi"); commit(&mut rgb); let glyphs = rgb.session.active().unwrap().doc.layers.last().unwrap().surface().unwrap().content_bounds(); @@ -643,7 +643,7 @@ mod indexed_commit_tests { let (layers_before, states_before) = (layers(&app), states(&app)); // Typing: the working layer is there, and shown, as measured. - pointer_up(&mut app, [80.0, 120.0], [80.0, 120.0]); + pointer_up(&mut app, [80.0, 120.0], [80.0, 120.0], egui::Modifiers::NONE); insert(&mut app, "Hi"); assert!(app.ui.text_edit.is_some(), "{mode}: the session is open"); assert_eq!(text_layers(&app), 1, "{mode}: the text is edited on a layer"); @@ -668,7 +668,7 @@ mod indexed_commit_tests { for mode in ["rgb", "indexed", "bitmap"] { let mut app = app(mode); let (layers_before, states_before) = (layers(&app), states(&app)); - pointer_up(&mut app, [80.0, 120.0], [80.0, 120.0]); + pointer_up(&mut app, [80.0, 120.0], [80.0, 120.0], egui::Modifiers::NONE); insert(&mut app, "Hi"); cancel(&mut app); assert!(app.ui.text_edit.is_none(), "{mode}: the session ended"); @@ -690,7 +690,7 @@ mod indexed_commit_tests { for mode in ["indexed", "bitmap"] { // A dragged paragraph box. let mut boxed = app(mode); - pointer_up(&mut boxed, [40.0, 60.0], [320.0, 180.0]); + pointer_up(&mut boxed, [40.0, 60.0], [320.0, 180.0], egui::Modifiers::NONE); insert(&mut boxed, "Hi"); let box_layer = LayerId(boxed.ui.text_edit.as_ref().unwrap().layer); assert!(matches!(text_of(&boxed, box_layer).map(|t| t.shape), Some(TextShape::Box { .. })), "{mode}: the setup made paragraph text"); @@ -701,7 +701,7 @@ mod indexed_commit_tests { // Vertical point text. let mut column_app = app(mode); column_app.ui.tool = Tool::VerticalType; - pointer_up(&mut column_app, [80.0, 120.0], [80.0, 120.0]); + pointer_up(&mut column_app, [80.0, 120.0], [80.0, 120.0], egui::Modifiers::NONE); insert(&mut column_app, "Hi"); let column = LayerId(column_app.ui.text_edit.as_ref().unwrap().layer); assert!(text_of(&column_app, column).is_some_and(|t| t.orientation == Orientation::Vertical), "{mode}: the setup made vertical text"); diff --git a/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs b/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs index bb80791b790..ce082b0c2d9 100644 --- a/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/font_commit_tests.rs @@ -86,7 +86,7 @@ fn fixture_renderer(new: bool, pattern: usize, character: bool, content: &str, g app.ui.tool = crate::state::Tool::Type; app.ui.tool_options.type_font = FONTS[pattern % 2].into(); app.ui.tool_options.type_size = 18.0; - super::pointer_up(app, [30.0, 70.0], [30.0, 70.0]); + super::pointer_up(app, [30.0, 70.0], [30.0, 70.0], egui::Modifiers::NONE); super::insert(app, content); let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer); let key = app.ui.text_edit.as_ref().unwrap().session.clone(); @@ -356,7 +356,7 @@ fn returning_focus_to_the_same_canvas_caret_keeps_the_chosen_typing_font() { let (x, top, bottom) = layout.caret(text.len()); let p = aff.apply(photocraft_geom::Point::new(f64::from(x) - 0.1, f64::from((top + bottom) * 0.5))); assert!(super::pointer_down(&mut h.state_mut().app, p.x, p.y, Modifiers::NONE)); - super::pointer_up(&mut h.state_mut().app, [p.x, p.y], [p.x, p.y]); + super::pointer_up(&mut h.state_mut().app, [p.x, p.y], [p.x, p.y], egui::Modifiers::NONE); assert_eq!(h.state().app.ui.text_edit.as_ref().unwrap().caret, 6); assert!(super::insertion_style::pending(&h.state().app).is_some()); h.ctx.memory_mut(|m| { diff --git a/crates/ui-egui/src/tools/type_tool/ime_tests.rs b/crates/ui-egui/src/tools/type_tool/ime_tests.rs index a63ede17a0d..20e6a85fa76 100644 --- a/crates/ui-egui/src/tools/type_tool/ime_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/ime_tests.rs @@ -13,7 +13,7 @@ fn app() -> PhotocraftApp { app.session.execute("file.new", json!({"width": 400, "height": 200})).unwrap(); app.sync_views(); app.ui.tool = crate::state::Tool::Type; - pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0]); + pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); insert(&mut app, "abc"); app } @@ -1338,7 +1338,7 @@ fn document_replacement_cannot_reuse_the_previous_documents_reset() { end_if_left(&mut app); assert!(app.ui.text_edit.is_none(), "the new document starts without the previous edit target"); app.ui.tool = crate::state::Tool::Type; - pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0]); + pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); insert(&mut app, "new"); assert_ne!(active_doc_id(&app), old_document); let before = layer_text(&app); diff --git a/crates/ui-egui/src/tools/type_tool/locked_layer_alert_tests.rs b/crates/ui-egui/src/tools/type_tool/locked_layer_alert_tests.rs index 3d0bc20228a..88a9b0fda80 100644 --- a/crates/ui-egui/src/tools/type_tool/locked_layer_alert_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/locked_layer_alert_tests.rs @@ -19,7 +19,7 @@ fn locked_text(lock: serde_json::Value) -> (PhotocraftApp, LayerId) { app.session.execute("file.new", json!({"width": 400, "height": 200})).unwrap(); app.sync_views(); app.ui.tool = crate::state::Tool::Type; - pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0]); + pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); insert(&mut app, "Locked text"); commit(&mut app); let id = active_layer(&app).unwrap(); @@ -94,7 +94,7 @@ fn a_click_on_empty_canvas_with_a_locked_text_layer_active_starts_new_text() { let (mut app, id) = locked_text(json!({"all": true})); app.run("layer.select", json!({"layer": id.0, "mode": "replace"})).unwrap(); assert!(!click(&mut app, OFF_TEXT), "no text there: the press is left to start new text"); - pointer_up(&mut app, [OFF_TEXT.0, OFF_TEXT.1], [OFF_TEXT.0, OFF_TEXT.1]); + pointer_up(&mut app, [OFF_TEXT.0, OFF_TEXT.1], [OFF_TEXT.0, OFF_TEXT.1], egui::Modifiers::NONE); assert!(error_dialogs(&app).is_empty()); let edit = app.ui.text_edit.as_ref().expect("new text is being edited"); assert!(edit.created); diff --git a/crates/ui-egui/src/tools/type_tool/mask_escape_tests.rs b/crates/ui-egui/src/tools/type_tool/mask_escape_tests.rs index a0fb1b45df8..638e7bd31d1 100644 --- a/crates/ui-egui/src/tools/type_tool/mask_escape_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/mask_escape_tests.rs @@ -25,7 +25,7 @@ fn new_app(tool: Tool, use_esc_to_commit: bool) -> PhotocraftApp { /// Start new text with a click and type `s`, as the canvas does. fn type_new(app: &mut PhotocraftApp, s: &str) -> LayerId { - super::pointer_up(app, [50.0, 100.0], [50.0, 100.0]); + super::pointer_up(app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); super::insert(app, s); LayerId(app.ui.text_edit.as_ref().unwrap().layer) } diff --git a/crates/ui-egui/src/tools/type_tool/pointer.rs b/crates/ui-egui/src/tools/type_tool/pointer.rs index 4c5b71cba58..1bec5947d21 100644 --- a/crates/ui-egui/src/tools/type_tool/pointer.rs +++ b/crates/ui-egui/src/tools/type_tool/pointer.rs @@ -319,22 +319,11 @@ fn makes_box(app: &PhotocraftApp, start: [f64; 2], end: [f64; 2]) -> bool { w >= min && h >= min } -/// Pointer up. `rect` is the dragged box (document px) when no edit session consumed the press. -pub fn pointer_up(app: &mut PhotocraftApp, start: [f64; 2], end: [f64; 2]) { - crate::type_box_preview::flush(app); - if let Some(e) = app.ui.text_edit.as_mut() { - e.dragging = false; - e.resize = None; - app.ui.caret_blink_time = app.last_frame_time; - return; - } - let (w, h) = ((end[0] - start[0]).abs(), (end[1] - start[1]).abs()); - let min = 4.0 / app.point_zoom().max(0.01) as f64; - let o = app.ui.tool_options.clone(); - let mask = app.ui.tool.is_type_mask(); - // A click (not a drag) with the Type tool on a path: area type inside a closed path, type - // on the path on its outline. The Type Mask tools ignore paths. - let target = if !mask && !makes_box(app, start, end) { path_target(app, start[0], start[1]) } else { None }; +/// The `type.create` parameters a Type-tool gesture ending now starts from: the placeholder or +/// empty text, the tool's orientation and the options bar's styles. The caller adds the geometry +/// (`box` for a dragged paragraph, `x`/`y` for point text), and [`create_layer`] adds the session's +/// `coalesce` key. +pub(crate) fn create_params(app: &PhotocraftApp) -> serde_json::Value { // Preferences ▸ Type: "Fill new type layers with placeholder text" (on by default). The // Horizontal Type Mask gets the Type tool's placeholder, as Photoshop's does (#12072); the // vertical mask's placeholder is not measured yet, so it keeps starting empty. @@ -343,54 +332,93 @@ pub fn pointer_up(app: &mut PhotocraftApp, start: [f64; 2], end: [f64; 2]) { let mut p = default_style_params(app); p["text"] = json!(text); p["orientation"] = json!(if app.ui.tool.is_vertical_type() { "vertical" } else { "horizontal" }); - if w >= min && h >= min { + p +} + +/// Create the type layer `p` describes, and finish what a released Type-tool gesture does with it: +/// the path target of a click, the options bar's antialiasing, the Type Mask tools' hidden working +/// layer, and the edit session with the placeholder selected. The id of the new layer, or why +/// creating it failed (the status bar already says so, since [`PhotocraftApp::run`] reported it). +pub(crate) fn create_layer(app: &mut PhotocraftApp, mut p: serde_json::Value, target: Option) -> Result { + let o = app.ui.tool_options.clone(); + let mask = app.ui.tool.is_type_mask(); + let n = p.get("text").and_then(serde_json::Value::as_str).unwrap_or("").chars().count(); + let key = session_key(app); + p["coalesce"] = json!(key); + let v = app.run("type.create", p)?; + let Some(id) = v.get("layer").and_then(serde_json::Value::as_u64) else { + return Err("type.create returned no layer".to_string()); + }; + // A failed follow-up leaves point text; say why instead of passing over it. + let follow_up = match &target { + Some(PathClick::Area { shape }) => app.run("type.fillPath", json!({"layer": id, "shape": shape, "coalesce": key})), + Some(PathClick::OnPath { shape, subpath, start }) => { + app.run("type.attachToPath", json!({"layer": id, "shape": shape, "subpath": subpath, "start": start, "coalesce": key})) + } + None => Ok(serde_json::Value::Null), + }; + if let Err(e) = follow_up { + app.ui.status = e; + app.ui.status_error = true; + } + if o.type_aa != "sharp" { + let _ = app.run("type.edit", json!({"layer": id, "antialias": o.type_aa, "coalesce": key})); + } + // A Type Mask's text is a hidden working layer: the canvas shows the mask overlay + // instead, and committing turns it into the selection. + if mask { + let _ = app.run("layer.setProps", json!({"layer": id, "visible": false, "coalesce": key})); + } + // Like Photoshop: the placeholder is selected, so typing replaces it. + app.ui.caret_blink_time = app.last_frame_time; + app.ui.text_edit = Some(TextEdit { + layer: id, + document: active_doc_id(app), + caret: n, + anchor: 0, + session: key, + created: true, + mask, + dragging: false, + resize: None, + preedit: None, + }); + app.ui.text_edit_return_tool = None; + Ok(id) +} + +/// Pointer up. `mods` are the modifiers held at the press of the gesture (`Drag::modifiers`); +/// `rect` is the dragged box (document px) when no edit session consumed the press. +pub fn pointer_up(app: &mut PhotocraftApp, start: [f64; 2], end: [f64; 2], mods: egui::Modifiers) { + crate::type_box_preview::flush(app); + if let Some(e) = app.ui.text_edit.as_mut() { + e.dragging = false; + e.resize = None; + app.ui.caret_blink_time = app.last_frame_time; + return; + } + let (w, h) = ((end[0] - start[0]).abs(), (end[1] - start[1]).abs()); + let box_drag = makes_box(app, start, end); + // Photoshop (#12044): Alt+drag with the Type tool sizes the new paragraph box in the + // Paragraph Text Size dialog instead of committing the drag, and its OK creates the text. + // Measured for the horizontal Type tool alone, so the vertical and Type Mask tools keep the + // plain drag; Alt+click (a drag too small for a box) stays point text. + if mods.alt && box_drag && app.ui.tool == crate::state::Tool::Type { + crate::paragraph_text_size::open(app, [start[0].min(end[0]), start[1].min(end[1])], w, h); + return; + } + let mask = app.ui.tool.is_type_mask(); + // A click (not a drag) with the Type tool on a path: area type inside a closed path, type + // on the path on its outline. The Type Mask tools ignore paths. + let target = if !mask && !box_drag { path_target(app, start[0], start[1]) } else { None }; + let mut p = create_params(app); + if box_drag { p["box"] = json!([start[0].min(end[0]).round(), start[1].min(end[1]).round(), w.round(), h.round()]); } else { p["x"] = json!(start[0].round()); p["y"] = json!(start[1].round()); } - let key = session_key(app); - p["coalesce"] = json!(key); - if let Ok(v) = app.run("type.create", p) - && let Some(id) = v.get("layer").and_then(serde_json::Value::as_u64) - { - // A failed follow-up leaves point text; say why instead of passing over it. - let follow_up = match &target { - Some(PathClick::Area { shape }) => app.run("type.fillPath", json!({"layer": id, "shape": shape, "coalesce": key})), - Some(PathClick::OnPath { shape, subpath, start }) => { - app.run("type.attachToPath", json!({"layer": id, "shape": shape, "subpath": subpath, "start": start, "coalesce": key})) - } - None => Ok(serde_json::Value::Null), - }; - if let Err(e) = follow_up { - app.ui.status = e; - app.ui.status_error = true; - } - if o.type_aa != "sharp" { - let _ = app.run("type.edit", json!({"layer": id, "antialias": o.type_aa, "coalesce": key})); - } - // A Type Mask's text is a hidden working layer: the canvas shows the mask overlay - // instead, and committing turns it into the selection. - if mask { - let _ = app.run("layer.setProps", json!({"layer": id, "visible": false, "coalesce": key})); - } - // Like Photoshop: the placeholder is selected, so typing replaces it. - let n = text.chars().count(); - app.ui.caret_blink_time = app.last_frame_time; - app.ui.text_edit = Some(TextEdit { - layer: id, - document: active_doc_id(app), - caret: n, - anchor: 0, - session: key, - created: true, - mask, - dragging: false, - resize: None, - preedit: None, - }); - app.ui.text_edit_return_tool = None; - } + let _ = create_layer(app, p, target); } /// Character index of the previous / next word boundary (shared with `type.navigate`). diff --git a/crates/ui-egui/src/tools/type_tool/tests.rs b/crates/ui-egui/src/tools/type_tool/tests.rs index dbcb62d6a55..29db5fef3a4 100644 --- a/crates/ui-egui/src/tools/type_tool/tests.rs +++ b/crates/ui-egui/src/tools/type_tool/tests.rs @@ -51,7 +51,7 @@ fn layer_text(app: &PhotocraftApp) -> String { /// A committed type layer reading `s` at the same spot as the others (stacked variants, #4320). fn stacked_variant(app: &mut PhotocraftApp, s: &str) -> LayerId { app.ui.text_edit = None; - pointer_up(app, [50.0, 100.0], [50.0, 100.0]); + pointer_up(app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); insert(app, s); commit(app); app.session.active().unwrap().active_layer.unwrap() @@ -132,7 +132,7 @@ fn move_double_click_edits_the_shown_variant_not_one_in_a_hidden_group() { #[test] fn shift_click_on_existing_type_starts_new_text() { let mut app = app(); - pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0]); + pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); insert(&mut app, "Existing words"); commit(&mut app); let existing = app.session.active().unwrap().doc.layers.last().unwrap().id; @@ -148,7 +148,7 @@ fn shift_click_on_existing_type_starts_new_text() { fn click_creates_placeholder_selected_and_typing_replaces_it() { let mut app = app(); assert!(!pointer_down(&mut app, 50.0, 100.0, egui::Modifiers::NONE)); - pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0]); + pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); let ed = app.ui.text_edit.clone().unwrap(); assert_eq!((ed.anchor, ed.caret), (0, PLACEHOLDER.chars().count())); insert(&mut app, "Héllo"); @@ -183,7 +183,7 @@ fn closed_path_forward_hit_after_last_caret() { app.ui.tool_options.type_align = align.into(); let path = photocraft_vector::shapes::rect(20.0, 20.0, 200.0, 100.0); app.run("path.set", json!({"path": photocraft_engine::vector_cmds::path_json(&path)})).unwrap(); - pointer_up(&mut app, [20.0, 45.0], [20.0, 45.0]); + pointer_up(&mut app, [20.0, 45.0], [20.0, 45.0], egui::Modifiers::NONE); insert(&mut app, "ssssssssssss"); let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer); let (l, _, _) = layout(&mut app, id).unwrap(); @@ -199,7 +199,7 @@ fn open_path_hits_keep_endpoint_clamping() { let mut app = app(); let path = photocraft_doc::vector::Path::new(vec![photocraft_doc::vector::Subpath::polyline(&[(20.0, 100.0), (380.0, 100.0)])]); app.run("path.set", json!({"path": photocraft_engine::vector_cmds::path_json(&path)})).unwrap(); - pointer_up(&mut app, [200.0, 100.0], [200.0, 100.0]); + pointer_up(&mut app, [200.0, 100.0], [200.0, 100.0], egui::Modifiers::NONE); insert(&mut app, "ssss"); let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer); assert_eq!(offset_at(&mut app, id, 198.0, 100.0), 0); @@ -214,7 +214,7 @@ fn closed_path_backward_hit_before_first_caret() { app.ui.tool_options.type_align = align.into(); let path = photocraft_vector::shapes::rect(20.0, 20.0, 200.0, 100.0); app.run("path.set", json!({"path": photocraft_engine::vector_cmds::path_json(&path)})).unwrap(); - pointer_up(&mut app, [20.0, 45.0], [20.0, 45.0]); + pointer_up(&mut app, [20.0, 45.0], [20.0, 45.0], egui::Modifiers::NONE); insert(&mut app, "ssssssssssss"); let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer); let (l, _, _) = layout(&mut app, id).unwrap(); @@ -232,7 +232,7 @@ fn closed_path_upstream_caret_rectangle_left_edge_roundtrip() { let mut app = app(); let path = photocraft_vector::shapes::rect(20.0, 20.0, 200.0, 100.0); app.run("path.set", json!({"path": photocraft_engine::vector_cmds::path_json(&path)})).unwrap(); - pointer_up(&mut app, [20.0, 45.0], [20.0, 45.0]); + pointer_up(&mut app, [20.0, 45.0], [20.0, 45.0], egui::Modifiers::NONE); insert(&mut app, "ssssssssssss"); let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer); let (layout, _, _) = layout(&mut app, id).unwrap(); @@ -282,7 +282,7 @@ fn click_on_a_path_starts_type_on_the_path() { assert!(path_target(&app, 200.0, 160.0).is_none(), "off the path"); let before = app.session.active().unwrap().history.entries().len(); assert!(!pointer_down(&mut app, 200.0, 101.0, egui::Modifiers::NONE)); - pointer_up(&mut app, [200.0, 101.0], [200.0, 101.0]); + pointer_up(&mut app, [200.0, 101.0], [200.0, 101.0], egui::Modifiers::NONE); let ed = app.ui.text_edit.clone().unwrap(); assert_eq!((ed.anchor, ed.caret), (0, PLACEHOLDER.chars().count()), "the placeholder is selected"); let shape = text_layer(&app.session.active().unwrap().doc, LayerId(ed.layer)).unwrap().shape.clone(); @@ -295,7 +295,7 @@ fn click_on_a_path_starts_type_on_the_path() { app.ui.tool = crate::state::Tool::VerticalType; assert!(!matches!(path_target(&app, 200.0, 101.0), Some(PathClick::OnPath { .. }))); app.ui.tool = crate::state::Tool::Type; - pointer_up(&mut app, [200.0, 160.0], [200.0, 160.0]); + pointer_up(&mut app, [200.0, 160.0], [200.0, 160.0], egui::Modifiers::NONE); let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer); assert_eq!(text_layer(&app.session.active().unwrap().doc, id).unwrap().shape, TextShape::Point); } @@ -311,7 +311,7 @@ fn caret_hits_type_on_a_path_along_the_curve() { Ok(()) }) .unwrap(); - pointer_up(&mut app, [300.0, 20.0], [300.0, 20.0]); + pointer_up(&mut app, [300.0, 20.0], [300.0, 20.0], egui::Modifiers::NONE); insert(&mut app, "ABCDEFGH"); let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer); assert!(matches!(text_layer(&app.session.active().unwrap().doc, id).unwrap().shape, photocraft_doc::text::TextShape::Path { .. })); @@ -342,7 +342,7 @@ fn type_unit_follows_the_units_and_rulers_preference() { fn placeholder_preference_controls_new_type_layer_text() { let mut app = app(); app.run("prefs.set", json!({"path": "type.fillNewTypeLayersWithPlaceholder", "value": false})).unwrap(); - pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0]); + pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); let ed = app.ui.text_edit.clone().unwrap(); assert_eq!((ed.anchor, ed.caret), (0, 0), "nothing to select"); assert_eq!(layer_text(&app), ""); @@ -369,7 +369,7 @@ fn smart_quotes_preference_controls_typed_quotes() { for (smart, expected) in [(true, "hi \u{201c}you\u{201d}"), (false, "hi \"you\"")] { let mut app = app(); app.run("prefs.set", json!({"path": "type.smartQuotes", "value": smart})).unwrap(); - pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0]); + pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); insert_typed(&mut app, "hi \"you\""); assert_eq!(layer_text(&app), expected, "smartQuotes={smart}"); } @@ -378,7 +378,7 @@ fn smart_quotes_preference_controls_typed_quotes() { #[test] fn a_name_from_text_after_blank_lines_keeps_following_the_text() { let mut app = app(); - pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0]); + pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); insert(&mut app, "\n\nTitle"); let id = app.ui.text_edit.as_ref().unwrap().layer; commit(&mut app); @@ -392,7 +392,7 @@ fn a_name_from_text_after_blank_lines_keeps_following_the_text() { #[test] fn dragging_a_box_handle_resizes_the_paragraph_box() { let mut app = app(); - pointer_up(&mut app, [10.0, 10.0], [110.0, 60.0]); + pointer_up(&mut app, [10.0, 10.0], [110.0, 60.0], egui::Modifiers::NONE); let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer); let steps = app.session.active().unwrap().history.entries().len(); // Top-left corner: the box keeps its bottom-right corner. @@ -400,7 +400,7 @@ fn dragging_a_box_handle_resizes_the_paragraph_box() { assert_eq!(app.ui.text_edit.as_ref().unwrap().resize.map(|r| r.handle), Some(0)); pointer_move(&mut app, 20.0, 25.0, egui::Modifiers::NONE); pointer_move(&mut app, 30.0, 30.0, egui::Modifiers::NONE); - pointer_up(&mut app, [10.0, 10.0], [30.0, 30.0]); + pointer_up(&mut app, [10.0, 10.0], [30.0, 30.0], egui::Modifiers::NONE); assert_eq!(box_shape(&app, id), Some((0.0, 0.0, 80.0, 30.0))); let aff = layout(&mut app, id).unwrap().1; assert_eq!((aff.m[4], aff.m[5]), (30.0, 30.0)); @@ -410,12 +410,12 @@ fn dragging_a_box_handle_resizes_the_paragraph_box() { // Right edge: only the width changes, and never below the minimum. assert!(pointer_down(&mut app, 110.0, 45.0, egui::Modifiers::NONE)); pointer_move(&mut app, 0.0, 99.0, egui::Modifiers::NONE); - pointer_up(&mut app, [110.0, 45.0], [0.0, 99.0]); + pointer_up(&mut app, [110.0, 45.0], [0.0, 99.0], egui::Modifiers::NONE); assert_eq!(box_shape(&app, id), Some((0.0, 0.0, MIN_BOX, 30.0))); // ⌥ mirrors the drag about the centre: the left edge follows the right one out. assert!(pointer_down(&mut app, 34.0, 45.0, egui::Modifiers::ALT)); pointer_move(&mut app, 70.0, 45.0, egui::Modifiers::ALT); - pointer_up(&mut app, [34.0, 45.0], [70.0, 45.0]); + pointer_up(&mut app, [34.0, 45.0], [70.0, 45.0], egui::Modifiers::NONE); assert_eq!(box_shape(&app, id), Some((0.0, 0.0, MIN_BOX + 72.0, 30.0))); let aff = layout(&mut app, id).unwrap().1; // Text space −36..40 (centre 2) through the translation: the doc centre stays at 32. @@ -425,7 +425,7 @@ fn dragging_a_box_handle_resizes_the_paragraph_box() { #[test] fn ime_preedit_is_replaced_by_each_update_and_commit_finalises() { let mut app = app(); - pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0]); + pointer_up(&mut app, [50.0, 100.0], [50.0, 100.0], egui::Modifiers::NONE); // Each preedit update replaces the previous one (and the placeholder selection first). ime_update(&mut app, "に", false); assert_eq!(layer_text(&app), "に"); @@ -454,7 +454,7 @@ fn ime_preedit_is_replaced_by_each_update_and_commit_finalises() { #[test] fn empty_new_layer_is_deleted_on_commit() { let mut app = app(); - pointer_up(&mut app, [10.0, 50.0], [10.0, 50.0]); + pointer_up(&mut app, [10.0, 50.0], [10.0, 50.0], egui::Modifiers::NONE); let n = app.session.active().unwrap().doc.layers.len(); insert(&mut app, ""); if let Some(e) = app.ui.text_edit.as_mut() { @@ -474,7 +474,7 @@ fn word_boundaries() { #[test] fn arrow_keys_reset_caret_blink_phase() { let mut app = app(); - pointer_up(&mut app, [10.0, 50.0], [10.0, 50.0]); + pointer_up(&mut app, [10.0, 50.0], [10.0, 50.0], egui::Modifiers::NONE); insert(&mut app, "Hello"); app.ui.caret_blink_time = 0.0; let ctx = egui::Context::default(); @@ -508,11 +508,11 @@ fn arrow_keys_reset_caret_blink_phase() { #[test] fn pointer_up_click_resets_caret_blink_phase() { let mut app = app(); - pointer_up(&mut app, [10.0, 50.0], [10.0, 50.0]); + pointer_up(&mut app, [10.0, 50.0], [10.0, 50.0], egui::Modifiers::NONE); insert(&mut app, "Hello"); app.ui.caret_blink_time = 0.0; app.last_frame_time = 12.3; - pointer_up(&mut app, [10.0, 50.0], [10.0, 50.0]); + pointer_up(&mut app, [10.0, 50.0], [10.0, 50.0], egui::Modifiers::NONE); assert_eq!(app.ui.caret_blink_time, 12.3); } @@ -561,7 +561,7 @@ fn closed_path_aligned_selection_highlights_every_visible_cluster() { app.ui.tool_options.type_align = align.into(); let path = photocraft_vector::shapes::rect(20.0, 20.0, 200.0, 100.0); app.run("path.set", json!({"path":photocraft_engine::vector_cmds::path_json(&path)})).unwrap(); - pointer_up(&mut app, [20.0, 45.0], [20.0, 45.0]); + pointer_up(&mut app, [20.0, 45.0], [20.0, 45.0], egui::Modifiers::NONE); insert(&mut app, "ssssssssssss"); let id = LayerId(app.ui.text_edit.as_ref().unwrap().layer); let (l, _, _) = layout(&mut app, id).unwrap(); diff --git a/crates/ui-egui/src/tools/type_tool/vertical_align_buttons_tests.rs b/crates/ui-egui/src/tools/type_tool/vertical_align_buttons_tests.rs index 25b99939432..007c744852b 100644 --- a/crates/ui-egui/src/tools/type_tool/vertical_align_buttons_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/vertical_align_buttons_tests.rs @@ -117,7 +117,7 @@ fn the_vertical_buttons_set_left_center_and_right_and_follow_the_paragraph() { fn the_horizontal_type_mask_tool_keeps_the_horizontal_buttons() { assert_eq!(shown(&bar(new_app(Tool::HorizontalTypeMask))), HORIZONTAL, "idle"); let mut app = new_app(Tool::HorizontalTypeMask); - super::pointer_up(&mut app, [400.0, 100.0], [400.0, 100.0]); + super::pointer_up(&mut app, [400.0, 100.0], [400.0, 100.0], egui::Modifiers::NONE); assert!(app.ui.text_edit.as_ref().is_some_and(|ed| ed.mask), "typing a mask"); assert_eq!(shown(&bar(app)), HORIZONTAL, "editing"); } diff --git a/crates/ui-egui/src/tools/type_tool/vertical_mask_align_buttons_tests.rs b/crates/ui-egui/src/tools/type_tool/vertical_mask_align_buttons_tests.rs index d92161045b9..5f7b6f6dd51 100644 --- a/crates/ui-egui/src/tools/type_tool/vertical_mask_align_buttons_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/vertical_mask_align_buttons_tests.rs @@ -13,7 +13,7 @@ use crate::state::Tool; /// The Vertical Type Mask tool typing a new mask; returns its hidden working layer. fn typing_a_mask(app: &mut PhotocraftApp) -> LayerId { - pointer_up(app, [400.0, 100.0], [400.0, 100.0]); + pointer_up(app, [400.0, 100.0], [400.0, 100.0], egui::Modifiers::NONE); let ed = app.ui.text_edit.as_ref().filter(|ed| ed.mask).expect("typing a mask"); LayerId(ed.layer) } From 09ccd2e9cd5e45f888f3257802d742070b5d9e93 Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sat, 14 Nov 2026 21:09:35 +0100 Subject: [PATCH 02/10] Alt+click on the new group button groups one active layer (#14717) Alt+click on the Layers panel's Create a new group button now opens New Group from Layers also with one non-Background layer active, and OK puts that layer into the group, as in Photoshop. With the Background or nothing active it still opens New Group (not measured). Fixes #14717 --- crates/ui-egui/src/new_group_button_tests.rs | 10 +- .../group_from_layers_alt_click_tests.rs | 123 ++++++++++++++++++ crates/ui-egui/src/panels/layers.rs | 11 +- 3 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 crates/ui-egui/src/panels/group_from_layers_alt_click_tests.rs diff --git a/crates/ui-egui/src/new_group_button_tests.rs b/crates/ui-egui/src/new_group_button_tests.rs index 54d8ff42a2e..5496607f19f 100644 --- a/crates/ui-egui/src/new_group_button_tests.rs +++ b/crates/ui-egui/src/new_group_button_tests.rs @@ -95,11 +95,11 @@ fn selecting_a_grouped_layer_opens_the_group() { assert!(rows.contains(&a.0) && rows.contains(&b.0), "{rows:?}"); } -/// ⌥-click asks in the New Group dialog first: New Group from Layers with several layers -/// selected, New Group with one. Nothing changes until OK. +/// ⌥-click asks in the New Group from Layers dialog first, with one layer selected too +/// (#14717). Nothing changes until OK. #[test] fn alt_click_opens_the_new_group_dialog() { - for (both, command) in [(true, "layer.new.groupFromLayers"), (false, "layer.new.group")] { + for (both, command) in [(true, "layer.new.groupFromLayers"), (false, "layer.new.groupFromLayers")] { let (mut h, a, b) = selected(both); h.get_by_label("Create a new group").click_modifiers(Modifiers::ALT); h.run_steps(4); @@ -114,7 +114,9 @@ fn alt_click_opens_the_new_group_dialog() { } else { let groups = groups(&h); assert_eq!(groups.len(), 1); - assert!(groups[0].children().unwrap().is_empty()); + assert_eq!(groups[0].children().unwrap().iter().map(|l| l.id).collect::>(), vec![b]); + let top: Vec = h.state().session.active().unwrap().doc.layers.iter().map(|l| l.id).collect(); + assert_eq!(top[1..], [a, groups[0].id]); } } } diff --git a/crates/ui-egui/src/panels/group_from_layers_alt_click_tests.rs b/crates/ui-egui/src/panels/group_from_layers_alt_click_tests.rs new file mode 100644 index 00000000000..12d9f59c121 --- /dev/null +++ b/crates/ui-egui/src/panels/group_from_layers_alt_click_tests.rs @@ -0,0 +1,123 @@ +//! #14717: ⌥-click on the Layers panel's "Create a new group" button opens New Group from Layers +//! and, on OK, puts the active layer into the new group also when it is the only selected layer, +//! as in Photoshop. With the Background or nothing active it keeps opening New Group (not +//! measured); plain, ⌘ and Shift clicks are unchanged. + +use egui::Modifiers; +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use photocraft_doc::{Layer, LayerId}; +use serde_json::json; + +use crate::PhotocraftApp; + +/// White Background, then Red, Green and Blue; only `active` is selected (`None`: no active layer). +fn document(active: Option<&str>) -> (Harness<'static, PhotocraftApp>, Vec) { + let mut s = photocraft_engine::Session::new(); + s.execute("prefs.set", json!({"path": "interface.language", "value": "en"})).unwrap(); + s.execute("file.new", json!({"width": 40, "height": 30, "background": "white"})).unwrap(); + let mut ids = vec![s.active().unwrap().doc.layers[0].id]; + for name in ["Red", "Green", "Blue"] { + ids.push(LayerId(s.execute("layer.new.layer", json!({"name": name})).unwrap()["layer"].as_u64().unwrap())); + } + match active { + Some(name) => { + let i = ["Background", "Red", "Green", "Blue"].iter().position(|n| *n == name).unwrap(); + s.execute("layer.select", json!({"layer": ids[i].0})).unwrap(); + } + None => { + s.execute("select.deselectLayers", json!({})).unwrap(); + } + } + let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).with_max_steps(64).build_eframe(|cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); + PhotocraftApp::new(s, crate::Services::default()) + }); + h.run_steps(4); + (h, ids) +} + +fn groups(h: &Harness<'static, PhotocraftApp>) -> Vec { + h.state().session.active().unwrap().doc.walk().into_iter().map(|(_, _, l)| l).filter(|l| l.is_group()).cloned().collect() +} + +/// ⌥-clicks the button and returns the opened dialog's id and command. +fn alt_click(h: &mut Harness<'static, PhotocraftApp>) -> (u64, String) { + h.get_by_label("Create a new group").click_modifiers(Modifiers::ALT); + h.run_steps(4); + assert!(groups(h).is_empty(), "nothing happens before OK"); + let d = h.state().ui.dialogs.last().expect("a group dialog opened"); + assert!(crate::new_group_ui::owns(&d.fields)); + (d.id, d.fields["__command"].as_str().unwrap_or_default().to_string()) +} + +#[test] +fn alt_click_with_one_layer_opens_new_group_from_layers_and_groups_it() { + let (mut h, ids) = document(Some("Blue")); + let (id, command) = alt_click(&mut h); + assert_eq!(command, crate::new_group_ui::FROM_LAYERS); + assert_eq!(h.state().ui.dialogs.last().unwrap().fields["__label"], "New Group from Layers…"); + crate::dialogs::confirm(h.state_mut(), id).unwrap(); + h.run_steps(4); + let groups = groups(&h); + assert_eq!(groups.len(), 1); + let children: Vec = groups[0].children().unwrap().iter().map(|l| l.id).collect(); + assert_eq!(children, vec![ids[3]], "Blue moves into the new group"); + let top: Vec = h.state().session.active().unwrap().doc.layers.iter().map(|l| l.id).collect(); + assert_eq!(top, vec![ids[0], ids[1], ids[2], groups[0].id], "the group takes Blue's place"); + assert_eq!(h.state().session.active().unwrap().selected_layers(), vec![groups[0].id]); +} + +#[test] +fn alt_click_with_one_lower_layer_groups_it_in_place() { + let (mut h, ids) = document(Some("Red")); + let (id, command) = alt_click(&mut h); + assert_eq!(command, crate::new_group_ui::FROM_LAYERS); + crate::dialogs::confirm(h.state_mut(), id).unwrap(); + h.run_steps(4); + let groups = groups(&h); + let children: Vec = groups[0].children().unwrap().iter().map(|l| l.id).collect(); + assert_eq!(children, vec![ids[1]]); + let top: Vec = h.state().session.active().unwrap().doc.layers.iter().map(|l| l.id).collect(); + assert_eq!(top, vec![ids[0], groups[0].id, ids[2], ids[3]]); +} + +/// Not measured: with the Background active, ⌥-click keeps opening New Group, and OK adds an +/// empty group. +#[test] +fn alt_click_with_the_background_active_keeps_opening_new_group() { + let (mut h, _) = document(Some("Background")); + let (id, command) = alt_click(&mut h); + assert_eq!(command, crate::new_group_ui::NEW_GROUP); + crate::dialogs::confirm(h.state_mut(), id).unwrap(); + h.run_steps(4); + assert!(groups(&h)[0].children().unwrap().is_empty()); +} + +/// Not measured: with nothing active, ⌥-click keeps opening New Group. +#[test] +fn alt_click_with_nothing_active_keeps_opening_new_group() { + let (mut h, _) = document(None); + assert!(h.state().session.active().unwrap().active_layer.is_none()); + let (_, command) = alt_click(&mut h); + assert_eq!(command, crate::new_group_ui::NEW_GROUP); +} + +/// With one layer selected a plain click still adds an empty group above it, and Shift-click +/// still groups it. +#[test] +fn plain_and_shift_click_with_one_layer_are_unchanged() { + let (mut h, _) = document(Some("Blue")); + h.get_by_label("Create a new group").click(); + h.run_steps(4); + assert!(h.state().ui.dialogs.is_empty()); + let g = groups(&h); + assert!(g[0].children().unwrap().is_empty()); + + let (mut h, ids) = document(Some("Blue")); + h.get_by_label("Create a new group").click_modifiers(Modifiers::SHIFT); + h.run_steps(4); + assert!(h.state().ui.dialogs.is_empty()); + let g = groups(&h); + assert_eq!(g[0].children().unwrap().iter().map(|l| l.id).collect::>(), vec![ids[3]]); +} diff --git a/crates/ui-egui/src/panels/layers.rs b/crates/ui-egui/src/panels/layers.rs index cc71b6884b4..e48656e9ecf 100644 --- a/crates/ui-egui/src/panels/layers.rs +++ b/crates/ui-egui/src/panels/layers.rs @@ -456,8 +456,11 @@ pub(super) fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let m = ui.input(|i| i.modifiers); let groups = (m.shift || selection.len() > 1) && active_layer.is_some(); if m.alt { - // Null params go through the menu path, which opens the dialog. - let cmd = if groups { crate::new_group_ui::FROM_LAYERS } else { crate::new_group_ui::NEW_GROUP }; + // Null params go through the menu path, which opens the dialog. Like Photoshop, + // ⌥-click asks for New Group from Layers also with one non-Background layer + // active, and OK puts that layer in the group (#14717). + let one = active_layer.is_some_and(|l| !doc.is_background(l.id)); + let cmd = if groups || one { crate::new_group_ui::FROM_LAYERS } else { crate::new_group_ui::NEW_GROUP }; actions.push((cmd.into(), Value::Null)); } else if m.command { actions.push(("layer.new.group".into(), json!({"position": "below"}))); @@ -621,3 +624,7 @@ pub(crate) fn fx_button(ui: &mut egui::Ui, size: f32, tip: &str) -> egui::Respon pub(super) fn channels(app: &mut PhotocraftApp, ui: &mut egui::Ui) { crate::channels_panel::show(app, ui); } + +#[cfg(test)] +#[path = "group_from_layers_alt_click_tests.rs"] +mod group_from_layers_alt_click_tests; From b03b1fd1be1a9c7a30ec06d83a3c93d68fe348fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hartmut=20N=C3=B6renberg?= Date: Sat, 14 Nov 2026 21:38:58 +0100 Subject: [PATCH 03/10] fix(ui-egui): the Paragraph Text Size dialog only creates text in the document it was opened for The dialog kept the dragged box but not the document, and OK created the layer in whichever document was active, so switching tabs after the Alt-drag put the text in the wrong one. The dialog now stores the document id when it opens, and OK refuses (closing the dialog, creating nothing) when another document is active. --- .../src/dialogs/paragraph_text_size.rs | 9 ++++++++ .../src/dialogs/paragraph_text_size/tests.rs | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/crates/ui-egui/src/dialogs/paragraph_text_size.rs b/crates/ui-egui/src/dialogs/paragraph_text_size.rs index d94fe396f11..5d5eebbc03f 100644 --- a/crates/ui-egui/src/dialogs/paragraph_text_size.rs +++ b/crates/ui-egui/src/dialogs/paragraph_text_size.rs @@ -22,6 +22,8 @@ const COMMAND: &str = "type.create"; /// The top-left the box was dragged from, in document pixels: OK puts the box there, whatever its /// size becomes in the dialog. const AT: &str = "__at"; +/// The document the drag was made in (its id): OK creates the text only while it is still the active one. +const DOCUMENT: &str = "__document"; /// Identify the Paragraph Text Size dialog fields. pub fn owns(fields: &Map) -> bool { @@ -36,6 +38,9 @@ pub fn open(app: &mut PhotocraftApp, at: [f64; 2], w: f64, h: f64) -> u64 { f.insert("__command".into(), json!(COMMAND)); f.insert("__label".into(), json!("Paragraph Text Size")); f.insert(AT.into(), json!([at[0], at[1]])); + if let Some(st) = app.session.active() { + f.insert(DOCUMENT.into(), json!(st.doc.id.0)); + } f.insert("width".into(), json!(w)); f.insert("height".into(), json!(h)); app.ui.open_dialog(DialogKind::Command, f) @@ -71,6 +76,10 @@ fn px_or(f: &Map, key: &str) -> f32 { /// OK: create the paragraph text the dialog sized, the same layer a plain drag of the same box /// would have made. pub fn confirm(app: &mut PhotocraftApp, f: &Map) -> Result { + // The box was dragged in one document: never put the text into another one that became active since. + if f.get(DOCUMENT).and_then(Value::as_u64) != app.session.active().map(|st| st.doc.id.0) { + return Err("the document the box was dragged in is no longer the active one".into()); + } let at = f.get(AT).and_then(Value::as_array); let (Some(x), Some(y)) = (at.as_ref().and_then(|a| a.first()).and_then(Value::as_f64), at.as_ref().and_then(|a| a.get(1)).and_then(Value::as_f64)) else { return Err("the Paragraph Text Size dialog has no position".into()); diff --git a/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs b/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs index 594b28d8576..86e189cfdf9 100644 --- a/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs +++ b/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs @@ -119,6 +119,27 @@ fn cancelling_creates_nothing() { assert!(h.state().ui.text_edit.is_none()); } +/// The dialog belongs to the document the Alt+drag was made in: when another document is active at +/// OK, nothing is created in it (or anywhere), and the dialog closes. +#[test] +fn confirming_after_another_document_became_active_creates_nothing() { + let mut app = app(); + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT); + let d = only_dialog(&app); + let first = app.session.active_index().unwrap(); + let first_layers = layers(&app); + app.run("file.new", json!({"width": 300, "height": 300})).unwrap(); + app.sync_views(); + assert_ne!(app.session.active_index(), Some(first), "the second document is active"); + let second_layers = layers(&app); + let r = crate::dialogs::confirm(&mut app, d); + assert!(r.is_err(), "OK in another document is refused: {r:?}"); + assert!(app.ui.dialogs.is_empty(), "the dialog closes"); + assert_eq!(layers(&app), second_layers, "nothing lands in the active document"); + assert!(app.session.set_active(first)); + assert_eq!(layers(&app), first_layers, "nor in the original one"); + assert!(app.ui.text_edit.is_none()); +} /// Not measured by the ticket, so unchanged: a drag without Alt still commits the box directly. #[test] fn a_plain_drag_still_makes_the_box_directly() { From e6a77592747a36e3a5d0c286f25f10375455ed0c Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:25:50 +0100 Subject: [PATCH 04/10] Regenerate docs/scorecard.md --- docs/scorecard.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/scorecard.md b/docs/scorecard.md index bd0456f0132..3f01a2ece7c 100644 --- a/docs/scorecard.md +++ b/docs/scorecard.md @@ -273,7 +273,7 @@ Menu wiring (`docs/parity-checklist.md`): 664 of 664 menu items live (100.0%). T | AUTO-219-5 | Batch: subfolders, open documents, naming template, progress/cancel, error log, stop | partial | [#219](https://github.com/storytold/photocraft/issues/219) | file_cmds/batch_run.rs and batch_naming.rs: flat subfolder output and last-result-wins names measured in Photoshop 2026; live open-document source; file naming components and serials; UTF-16 LE error log; stop-on-error; CLI and Batch dialog, #4579. Desktop Esc asks Continue/Stop, retaining one plan and error log; a read-only canvas preview shows each scratch-session input without a progress bar. Inputs are not live tabs with Layers panel content, so full window parity remains open. | | AUTO-219-6 | Plug-in ABI v2: panel kind, progress/cancel calls, read other layers, Last Filter repeats | missing | [#219](https://github.com/storytold/photocraft/issues/219) | runtime.rs:15 ABI_VERSION = 1; manifest.rs:18 Kind::Filter only | | AUTO-219-7 | Local ONNX models behind a flag, managed in Preferences; subject select, background removal | missing | [#219](https://github.com/storytold/photocraft/issues/219) | No ONNX runtime dependency | -| AUTO-219-8 | xtask check that every panel button routes through a command id | partial | [#219](https://github.com/storytold/photocraft/issues/219) | cargo xtask panel-commands (run by xtask ci and CI) fails on a shell click handler that changes the document or session directly; 1 allowlisted function left (panels/color.rs color_field assigns the foreground/background colour instead of tools.setColors) | +| AUTO-219-8 | xtask check that every panel button routes through a command id | partial | [#219](https://github.com/storytold/photocraft/issues/219) | cargo xtask panel-commands (run by xtask ci and CI) fails on a shell click handler that changes the document or session directly; no allowlisted function left (the Color panel field dispatches tools.setColors) | | AUTO-219-9 | Headless commands for in-canvas type editing, Liquify/Puppet strokes, transform handles | done | [#219](https://github.com/storytold/photocraft/issues/219) | type.hitTest, type.caret, type.navigate; filter.liquify strokes, edit.puppetWarp pins, type.edit, edit.transform | | AUTO-219-10 | Agent acceptance suite grown to 30-50 workflows | partial | [#219](https://github.com/storytold/photocraft/issues/219) | automation/tests/it/agent_tasks.rs runs 10 workflows over MCP | | AUTO-MCP-LIVE | Connect an MCP client to the running app without a terminal (no flags, ports or tokens to copy) | done | | 2026-11-12 (#5525, #11363, craft-ai-integrations#195): the ArtCraft Launcher's agents switch (the one consent; read through craft-ai-agents) starts and stops the loopback control server while the app runs (no restart) and publishes agent-connection.json; plain photocraft-cli mcp works in the open app on every call while agents are allowed (launch / headless / error while it is closed) and headless otherwise (--headless forces it); the launcher's Add buttons register every Craft app, PhotoCraft writes no client configuration. automation/tests/mcp_live.rs, ui-egui prefs_ui/agents_tests.rs, craft-automation tests/it/agents.rs | From 91f5f371a9780dbd2bbda49f915236cb48beb81f Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Wed, 18 Nov 2026 18:14:43 +0100 Subject: [PATCH 05/10] test(ui-egui): pin the Paragraph Text Size rule at the press of the gesture #12044: the Alt+drag rule reads the modifier from the press of the gesture, so both mid-drag directions are pinned: letting Alt up before the release still opens the dialog, and pressing Alt only as the button comes up stays today's plain drag. The drag helper now takes separate Down and Up modifiers. Two further guards pin today's behaviour around the dialog: a second drag while the dialog is open creates nothing, and a name the dialog does not show as a field is refused by set_json_field. The app() helper follows main's boxed app. --- .../src/dialogs/paragraph_text_size/tests.rs | 88 +++++++++++++++---- 1 file changed, 73 insertions(+), 15 deletions(-) diff --git a/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs b/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs index 840fc50a60f..77dc03f498d 100644 --- a/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs +++ b/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs @@ -1,7 +1,9 @@ //! Alt+drag with the Type tool and the Paragraph Text Size dialog it opens (#12044): the dialog is //! measured (prefilled with the dragged size, decimals kept, OK creates the box at the drag start, -//! Cancel creates nothing), and the two unmeasured neighbours of that route are checked to keep -//! today's behaviour: a plain drag still makes the box directly, and Alt+click is still point text. +//! Cancel creates nothing), and the neighbours of that route are checked to keep today's behaviour: +//! a plain drag still makes the box directly, Alt+click is still point text, ⌥ is read at the press +//! so it can come up or go down mid-drag, and a second drag while the dialog is open is swallowed +//! by that dialog. //! //! The gestures go through the canvas pass (`canvas::testing`), the way the released Type tool does //! on the hosted framework: a press with ⌥ held, a move, a release. The dialog is driven the way a @@ -19,7 +21,7 @@ use crate::state::Tool; use crate::type_tool::PLACEHOLDER; /// A 400 × 200 document with the Type tool ready. -fn app() -> PhotocraftApp { +fn app() -> Box { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); app.run("file.new", json!({"width": 400, "height": 200})).unwrap(); app.sync_views(); @@ -27,14 +29,15 @@ fn app() -> PhotocraftApp { app } -/// Press at `from`, drag to `to` and release, holding `mods` through the gesture, as the canvas -/// pass sees it: the Alt+drag rule reads ⌥ from the press of the gesture. -fn drag(app: &mut PhotocraftApp, from: [f64; 2], to: [f64; 2], mods: Modifiers) { - tool_event(app, ToolEvent::Down { x: from[0], y: from[1], pressure: 1.0 }, mods); +/// Press at `from` with `down` held, drag to `to` and release with `up` held, as the canvas pass +/// sees it (the move carries `up`, the state just before the release). ⌥ can change mid-gesture: +/// the Alt+drag rule reads it from the press, and these two modifiers are how a test says so. +fn drag(app: &mut PhotocraftApp, from: [f64; 2], to: [f64; 2], down: Modifiers, up: Modifiers) { + tool_event(app, ToolEvent::Down { x: from[0], y: from[1], pressure: 1.0 }, down); if from != to { - tool_event(app, ToolEvent::Move { x: to[0], y: to[1], pressure: 1.0 }, mods); + tool_event(app, ToolEvent::Move { x: to[0], y: to[1], pressure: 1.0 }, up); } - tool_event(app, ToolEvent::Up { x: to[0], y: to[1] }, mods); + tool_event(app, ToolEvent::Up { x: to[0], y: to[1] }, up); } fn layers(app: &PhotocraftApp) -> usize { @@ -82,7 +85,7 @@ fn box_rect(app: &PhotocraftApp, id: u64) -> [f64; 4] { fn alt_drag_opens_the_dialog_prefilled_with_the_dragged_size() { let mut app = app(); let before = layers(&app); - drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT); + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT, Modifiers::ALT); let (_id, f) = only_dialog(&app); assert_eq!((f["width"].as_f64(), f["height"].as_f64()), (Some(99.5), Some(50.0)), "the dragged size, decimals kept"); assert_eq!(layers(&app), before, "the drag itself creates nothing"); @@ -94,7 +97,7 @@ fn alt_drag_opens_the_dialog_prefilled_with_the_dragged_size() { #[test] fn confirming_creates_the_paragraph_box_at_the_drag_start() { let mut app = app(); - drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT); + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT, Modifiers::ALT); let (d, _) = only_dialog(&app); set(&mut app, d, [("width", json!(250.0)), ("height", json!(120.0))]); let ctx = app.ctx().clone(); @@ -111,7 +114,7 @@ fn confirming_creates_the_paragraph_box_at_the_drag_start() { #[test] fn cancelling_creates_nothing() { let mut app = app(); - drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT); + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT, Modifiers::ALT); let (id, _) = only_dialog(&app); let before = layers(&app); let ctx = app.ctx().clone(); @@ -127,7 +130,7 @@ fn cancelling_creates_nothing() { #[test] fn confirming_after_another_document_became_active_creates_nothing() { let mut app = app(); - drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT); + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT, Modifiers::ALT); let (d, _) = only_dialog(&app); let first = app.session.active_index().unwrap(); let first_layers = layers(&app); @@ -149,7 +152,7 @@ fn confirming_after_another_document_became_active_creates_nothing() { #[test] fn a_plain_drag_still_makes_the_box_directly() { let mut app = app(); - drag(&mut app, [10.0, 10.0], [110.0, 60.0], Modifiers::NONE); + drag(&mut app, [10.0, 10.0], [110.0, 60.0], Modifiers::NONE, Modifiers::NONE); assert!(app.framework.dialogs.open_dialogs().is_empty(), "a plain drag opens no dialog"); let ed = app.ui.text_edit.as_ref().expect("the drag creates the text at once"); assert_eq!(box_rect(&app, ed.layer), [10.0, 10.0, 100.0, 50.0]); @@ -159,10 +162,65 @@ fn a_plain_drag_still_makes_the_box_directly() { #[test] fn an_alt_click_is_still_point_text() { let mut app = app(); - drag(&mut app, [50.0, 100.0], [50.0, 100.0], Modifiers::ALT); + drag(&mut app, [50.0, 100.0], [50.0, 100.0], Modifiers::ALT, Modifiers::ALT); assert!(app.framework.dialogs.open_dialogs().is_empty(), "a click opens no dialog"); let ed = app.ui.text_edit.as_ref().expect("the click creates point text"); let t = text(&app, ed.layer); assert!(matches!(t.shape, photocraft_doc::text::TextShape::Point), "point text"); assert_eq!([t.transform.m[4], t.transform.m[5]], [50.0, 100.0]); } + +/// Guard (pattern 8, the order of checks): ⌥ is read at the press of the gesture, so letting it up +/// mid-drag does not take the dialog away. Pinning the chosen latch, so it passes with the rule read +/// at the release too only if that rule were in the code: with the release read instead, this drag +/// has no ⌥ left at the release and no dialog opens - seen red. +#[test] +fn alt_released_mid_drag_still_opens_the_dialog() { + let mut app = app(); + let before = layers(&app); + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT, Modifiers::NONE); + let (_id, f) = only_dialog(&app); + assert_eq!((f["width"].as_f64(), f["height"].as_f64()), (Some(99.5), Some(50.0)), "the dragged size, decimals kept"); + assert_eq!(layers(&app), before, "the drag itself still creates nothing"); + assert!(app.ui.text_edit.is_none(), "and still starts no edit session"); +} + +/// The same latch the other way, guard as well: ⌥ pressed only as the button comes up opens nothing, +/// the gesture stays today's plain drag (rounded to the pixel, as it has always been). +#[test] +fn alt_pressed_mid_drag_makes_the_plain_box_instead() { + let mut app = app(); + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::NONE, Modifiers::ALT); + assert!(app.framework.dialogs.open_dialogs().is_empty(), "⌥ pressed mid-drag opens no dialog"); + let ed = app.ui.text_edit.as_ref().expect("the drag creates the text at once"); + assert_eq!(box_rect(&app, ed.layer), [10.0, 10.0, 100.0, 50.0], "the plain drag's rounded box"); +} + +/// Guard: the dialog the first drag opened stays the only one, and a second canvas gesture while it +/// is open reaches neither the rule nor `type.create`: nothing is created, nothing is edited. +#[test] +fn a_second_drag_while_the_dialog_is_open_creates_nothing() { + let mut app = app(); + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT, Modifiers::ALT); + let (_id, _) = only_dialog(&app); + let before = layers(&app); + drag(&mut app, [200.0, 20.0], [260.0, 70.0], Modifiers::ALT, Modifiers::ALT); + assert_eq!(app.framework.dialogs.open_dialogs().len(), 1, "the second drag opens no second dialog"); + assert_eq!(layers(&app), before, "and creates nothing"); + assert!(app.ui.text_edit.is_none(), "and starts no edit session"); +} + +/// Guard (pattern 9, no guessing from a name): the drag's top-left and the document it was made in +/// are the family's captured value, not fields - a control `set_json_field` for a name the dialog +/// does not show is refused, so the geometry cannot be pushed in through the field map. +#[test] +fn a_name_the_dialog_does_not_show_as_a_field_is_refused() { + let mut app = app(); + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT, Modifiers::ALT); + let (id, _) = only_dialog(&app); + let ctx = app.ctx().clone(); + for field in ["at", "document", "box", "text"] { + assert!(app.framework.dialogs.set_json_field(&ctx, id, field, json!(1.0)).is_err(), "`{field}` is not a field of this dialog"); + } + assert_eq!(only_dialog(&app).1["width"].as_f64(), Some(99.5), "and the two real fields keep the dragged size"); +} From f7b46ee40a73926171e266dc6dad9a4ba0c96054 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Wed, 18 Nov 2026 18:29:33 +0100 Subject: [PATCH 06/10] test(ui-egui): pin the Paragraph Text Size neighbours on the framework route #12044: three more guards around the Alt+drag dialog. The rule is gated on the measured tool, so an Alt+drag with the vertical Type tool keeps today's plain drag. The drag's top-left and its document are the family's captured value, not fields, so a control set_json_field for a name the dialog does not show is refused. And the ticket's history wording is now measured on the gesture: OK adds one History state, Cancel adds none. --- .../src/dialogs/paragraph_text_size/tests.rs | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs b/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs index 77dc03f498d..5b2fed9b02d 100644 --- a/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs +++ b/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs @@ -1,9 +1,10 @@ //! Alt+drag with the Type tool and the Paragraph Text Size dialog it opens (#12044): the dialog is -//! measured (prefilled with the dragged size, decimals kept, OK creates the box at the drag start, -//! Cancel creates nothing), and the neighbours of that route are checked to keep today's behaviour: -//! a plain drag still makes the box directly, Alt+click is still point text, ⌥ is read at the press -//! so it can come up or go down mid-drag, and a second drag while the dialog is open is swallowed -//! by that dialog. +//! measured (prefilled with the dragged size, decimals kept, OK creates the box at the drag start +//! and adds one History state, Cancel creates nothing and adds none), and the neighbours of that +//! route are checked to keep today's behaviour: a plain drag still makes the box directly, Alt+click +//! is still point text, the vertical Type tool keeps its plain drag, ⌥ is read at the press so it can +//! come up or go down mid-drag, a second drag while the dialog is open is swallowed by that dialog, +//! and a name the dialog does not show as a field is refused. //! //! The gestures go through the canvas pass (`canvas::testing`), the way the released Type tool does //! on the hosted framework: a press with ⌥ held, a move, a release. The dialog is driven the way a @@ -44,6 +45,11 @@ fn layers(app: &PhotocraftApp) -> usize { app.session.active().unwrap().doc.layers.len() } +/// The active document's History entries: the ticket's "adds no history state" is measured here. +fn history_len(app: &PhotocraftApp) -> usize { + app.session.active().unwrap().history.entries().len() +} + /// The open hosted dialogs: id, key and fields. Asserts that the Alt+drag opened one dialog and /// that it is the Paragraph Text Size family's. fn only_dialog(app: &PhotocraftApp) -> (DialogId, Value) { @@ -100,9 +106,11 @@ fn confirming_creates_the_paragraph_box_at_the_drag_start() { drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT, Modifiers::ALT); let (d, _) = only_dialog(&app); set(&mut app, d, [("width", json!(250.0)), ("height", json!(120.0))]); + let steps = history_len(&app); let ctx = app.ctx().clone(); crate::dialogs::confirm(&mut app, &ctx, d).unwrap(); assert!(app.framework.dialogs.open_dialogs().is_empty(), "OK closes the dialog"); + assert_eq!(history_len(&app), steps + 1, "OK adds one History state, as the drag's create does"); let ed = app.ui.text_edit.as_ref().expect("OK starts the edit session, as the drag does"); assert_eq!(box_rect(&app, ed.layer), [10.0, 10.0, 250.0, 120.0], "the dialog's box at the drag's start"); assert_eq!((ed.anchor, ed.caret), (0, PLACEHOLDER.chars().count()), "placeholder text, all of it selected"); @@ -117,11 +125,13 @@ fn cancelling_creates_nothing() { drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT, Modifiers::ALT); let (id, _) = only_dialog(&app); let before = layers(&app); + let steps = history_len(&app); let ctx = app.ctx().clone(); app.framework.dialogs.cancel_by_id(&ctx, id); frame(&mut app); assert!(app.framework.dialogs.open_dialogs().is_empty(), "Cancel closes the dialog"); assert_eq!(layers(&app), before, "Cancel creates nothing"); + assert_eq!(history_len(&app), steps, "and adds no History state"); assert!(app.ui.text_edit.is_none()); } @@ -210,6 +220,18 @@ fn a_second_drag_while_the_dialog_is_open_creates_nothing() { assert!(app.ui.text_edit.is_none(), "and starts no edit session"); } +/// Guard (pattern 4, scope): the ticket measured the horizontal Type tool alone, so the vertical one +/// keeps today's gesture - an Alt+drag there still commits the box at once, with no dialog. +#[test] +fn an_alt_drag_with_the_vertical_type_tool_still_makes_the_box_directly() { + let mut app = app(); + app.ui.tool = Tool::VerticalType; + drag(&mut app, [10.0, 10.0], [110.0, 60.0], Modifiers::ALT, Modifiers::ALT); + assert!(app.framework.dialogs.open_dialogs().is_empty(), "the vertical Type tool opens no dialog"); + let ed = app.ui.text_edit.as_ref().expect("the drag creates the text at once"); + assert_eq!(box_rect(&app, ed.layer), [10.0, 10.0, 100.0, 50.0], "the plain drag's box"); +} + /// Guard (pattern 9, no guessing from a name): the drag's top-left and the document it was made in /// are the family's captured value, not fields - a control `set_json_field` for a name the dialog /// does not show is refused, so the geometry cannot be pushed in through the field map. From 523df5804c6dafba88bae77ae6dd9936374dad57 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 21 Nov 2026 05:23:56 -0600 Subject: [PATCH 07/10] Magic Eraser: its own icon cursor With Standard Other Cursors the Magic Eraser's cursor is its toolbar icon, the hotspot on the eraser's end at the lower left of the glyph, also with Shift held. Precise Other Cursors and Caps Lock keep the crosshair, as for the Paint Bucket. Fixes #12001 --- crates/ui-egui/src/canvas/cursor_policy.rs | 15 +++++-- .../src/canvas/magic_eraser_cursor_tests.rs | 45 +++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs diff --git a/crates/ui-egui/src/canvas/cursor_policy.rs b/crates/ui-egui/src/canvas/cursor_policy.rs index f5e61808771..5aac0cc5f0a 100644 --- a/crates/ui-egui/src/canvas/cursor_policy.rs +++ b/crates/ui-egui/src/canvas/cursor_policy.rs @@ -50,17 +50,22 @@ pub(crate) fn sample_target() -> Cursor { /// The pointer of a painting tool that acts on a click and has no brush tip: the Paint Bucket's /// arrow with the bucket below right of it, the hotspot on the arrow's tip, so a click fills the -/// pixel under the tip (#12539), and the Magic Eraser's crosshair. Precise Other Cursors (or Caps -/// Lock, `precise`) gives the Paint Bucket the crosshair too (#3968). `None` for a tool that -/// strokes with the brush. +/// pixel under the tip (#12539), and the Magic Eraser's own icon with the hotspot on the eraser's +/// end at the lower left (#12001). Precise Other Cursors (or Caps Lock, `precise`) gives both the +/// crosshair (#3968). `None` for a tool that strokes with the brush. pub(crate) fn click_tool_cursor(tool: Tool, precise: bool) -> Option { match tool { Tool::PaintBucket if !precise => Some(Cursor::Painted(PaintedCursor::pointer_tool(PointerGlyph::Arrow, crate::icons::tool_icon(tool)))), + Tool::MagicEraser if !precise => Some(Cursor::Painted(PaintedCursor::tool(crate::icons::tool_icon(tool), MAGIC_ERASER_HOTSPOT, None))), Tool::PaintBucket | Tool::MagicEraser => Some(Cursor::Painted(PaintedCursor::Crosshair)), _ => None, } } +/// The Magic Eraser icon's point that sits on the pointer, in its 24-unit box: the middle of the eraser's end, which +/// lies at the lower left of the `eraser_magic` glyph (#12001). +pub(crate) const MAGIC_ERASER_HOTSPOT: egui::Vec2 = egui::vec2(4.6, 18.4); + /// Path Selection's own pointer (#13295): the light arrow, and the solid one with ⌥ (without ⌘) /// where a press would land on a component (`path_components::over_component`). ⌘ keeps the light /// one; Precise Other Cursors (or Caps Lock, `precise`) the crosshair. `mods` and `at` are the @@ -161,3 +166,7 @@ mod triangle_alt_eyedropper_tests; #[cfg(test)] #[path = "custom_shape_alt_eyedropper_tests.rs"] mod custom_shape_alt_eyedropper_tests; + +#[cfg(test)] +#[path = "magic_eraser_cursor_tests.rs"] +mod magic_eraser_cursor_tests; diff --git a/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs b/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs new file mode 100644 index 00000000000..55cf2e5701e --- /dev/null +++ b/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs @@ -0,0 +1,45 @@ +//! #12001: the Magic Eraser's cursor is its own toolbar icon with the hotspot on the eraser's end at the lower left, +//! also with Shift held; Precise Other Cursors and Caps Lock give the crosshair. Driven through real egui input on +//! the real canvas; the assertions read the cursor the tool asked the tool host for. + +use craft::behavior::{Cursor, PaintedCursor}; +use craft::ui::runtime::windows::WindowHost; +use egui::Modifiers; +use egui_kittest::Harness; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::guide_cursor_tests::{harness, hover}; +use crate::state::Tool; + +/// A point away from the harness's guide at x = 200. +const AT: [f32; 2] = [100.0, 150.0]; + +fn cursor_with(h: &mut Harness<'static, Box>, mods: Modifiers) -> Option { + hover(h, AT[0], AT[1], mods); + h.state().canvas_tools.last_response.as_ref().and_then(|r| r.cursor.clone()) +} + +#[test] +fn the_standard_cursor_is_the_magic_eraser_icon_with_its_tip_at_the_lower_left() { + let mut h = harness(Tool::MagicEraser); + let Some(Cursor::Painted(PaintedCursor::Tool { icon, hotspot, badge, .. })) = cursor_with(&mut h, Modifiers::NONE) else { + panic!("an icon cursor, not the crosshair"); + }; + assert_eq!(icon, crate::icons::tool_icon(Tool::MagicEraser), "the toolbar's own icon"); + assert!(hotspot.x < 12.0 && hotspot.y > 12.0, "the hotspot sits at the lower left of the 24-unit box: {hotspot:?}"); + assert!(badge.is_none()); + assert_eq!(cursor_with(&mut h, Modifiers::SHIFT), cursor_with(&mut h, Modifiers::NONE), "Shift keeps it"); +} + +#[test] +fn precise_other_cursors_and_caps_lock_give_the_crosshair() { + let mut h = harness(Tool::MagicEraser); + let crosshair = Some(Cursor::Painted(PaintedCursor::Crosshair)); + h.state_mut().run("prefs.set", json!({"path": "cursors.other", "value": "precise"})).unwrap(); + assert_eq!(cursor_with(&mut h, Modifiers::NONE), crosshair, "Precise: the crosshair"); + h.state_mut().run("prefs.set", json!({"path": "cursors.other", "value": "standard"})).unwrap(); + assert_ne!(cursor_with(&mut h, Modifiers::NONE), crosshair, "Standard again: the icon"); + WindowHost::of(&h.ctx).set_caps_lock(Some(true)); + assert_eq!(cursor_with(&mut h, Modifiers::NONE), crosshair, "Caps Lock: the crosshair"); +} From 92345d222ac6491607b705c269afb989d385de2e Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 21 Nov 2026 12:36:06 -0600 Subject: [PATCH 08/10] Magic Eraser cursor test: pin the hotspot by value (CodeRabbit on #16251) --- crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs b/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs index 55cf2e5701e..aed908d1fe9 100644 --- a/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs +++ b/crates/ui-egui/src/canvas/magic_eraser_cursor_tests.rs @@ -27,7 +27,8 @@ fn the_standard_cursor_is_the_magic_eraser_icon_with_its_tip_at_the_lower_left() panic!("an icon cursor, not the crosshair"); }; assert_eq!(icon, crate::icons::tool_icon(Tool::MagicEraser), "the toolbar's own icon"); - assert!(hotspot.x < 12.0 && hotspot.y > 12.0, "the hotspot sits at the lower left of the 24-unit box: {hotspot:?}"); + // The eraser end of the glyph, at the lower left of its 24-unit box: pinned by value so a moved constant fails. + assert_eq!(hotspot, egui::vec2(4.6, 18.4), "the eraser tip"); assert!(badge.is_none()); assert_eq!(cursor_with(&mut h, Modifiers::SHIFT), cursor_with(&mut h, Modifiers::NONE), "Shift keeps it"); } From 5bc88ca51dddc75a51ba205f0273bb6315b73272 Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Mon, 23 Nov 2026 23:17:59 +0100 Subject: [PATCH 09/10] Layers footer: Alt-click with a lone artboard keeps New Group An artboard can't go into a group, so New Group from Layers failed on OK when an artboard was the only active layer and no group was made. The single-layer route of #14717 now leaves artboards out, so a lone artboard gets the New Group dialog and its empty group as before. --- crates/ui-egui/src/layers_footer_tests.rs | 21 +++++++++++++++++++++ crates/ui-egui/src/panels/layers_events.rs | 5 +++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/layers_footer_tests.rs b/crates/ui-egui/src/layers_footer_tests.rs index 1a2619e0336..bbbc2ddf517 100644 --- a/crates/ui-egui/src/layers_footer_tests.rs +++ b/crates/ui-egui/src/layers_footer_tests.rs @@ -235,6 +235,27 @@ fn footer_buttons_run_photocraft_commands() { assert!(groups(h)[0].children().unwrap().is_empty()); }, }, + Case { + case: "Alt New Group, one artboard active: an empty group, the artboard stays a board", + doc: || { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 200, "height": 100})).unwrap(); + s.execute("layer.new.artboard", json!({"name": "Board", "rect": [0, 0, 100, 100]})).unwrap(); + s + }, + before: none, + button: "Create a new group", + mods: Modifiers::ALT, + after: |h| { + let id = h.state().framework.dialogs.stack().top().expect("the New Group dialog opened"); + confirm(h, id); + h.run_steps(4); + let plain: Vec = groups(h).into_iter().filter(|g| g.artboard().is_none()).collect(); + assert_eq!(plain.len(), 1, "OK adds one group: {:?}", top(h)); + assert!(plain[0].children().unwrap().is_empty()); + assert!(doc(h).layers.iter().any(|l| l.artboard().is_some()), "the artboard stays at the top level"); + }, + }, Case { case: "Cmd New Group, two selected: an empty group below the active layer", doc: || two(true), diff --git a/crates/ui-egui/src/panels/layers_events.rs b/crates/ui-egui/src/panels/layers_events.rs index 85a7a4f25f9..36344f5f94c 100644 --- a/crates/ui-egui/src/panels/layers_events.rs +++ b/crates/ui-egui/src/panels/layers_events.rs @@ -496,8 +496,9 @@ fn footer(app: &mut PhotocraftApp, picked: Option, if ask { // Null params go through the menu path, which opens the dialog. Like Photoshop, // ⌥-click asks for New Group from Layers also with one non-Background layer - // active, and OK puts that layer in the group (#14717). - let one = active.is_some_and(|l| !doc.is_background(l.id)); + // active, and OK puts that layer in the group (#14717). An artboard can't go into + // a group, so a lone artboard keeps New Group. + let one = active.is_some_and(|l| !doc.is_background(l.id) && l.artboard().is_none()); let cmd = if groups || one { crate::new_group_ui::FROM_LAYERS } else { crate::new_group_ui::NEW_GROUP }; actions.push((cmd.into(), Value::Null)); } else if below { From 3765708ac79795212973a6625b49d3e554dc3cb0 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Tue, 24 Nov 2026 00:47:14 +0100 Subject: [PATCH 10/10] feat(ui-egui): the Paragraph Text Size dialog creates from a settings snapshot #12044 review: the reference application's dialog is modal, so nothing can change the tool or its options between the Alt+drag and OK, and the box it makes always uses what was active at the drag. open() now snapshots the tool (horizontal or vertical), the type options and the placeholder preference into the family's captured value, and OK hands that snapshot to create_params and create_layer instead of reading the live app. A control that switches to the vertical Type tool, edits the font size or turns the placeholder preference off while the dialog is open therefore cannot leak into the new layer. A plain drag and a click take the snapshot at their own release, so they keep reading the live settings as they do today; both are pinned. --- .../src/dialogs/paragraph_text_size.rs | 31 +++++-- .../src/dialogs/paragraph_text_size/tests.rs | 90 +++++++++++++++++-- crates/ui-egui/src/tools/type_tool.rs | 2 +- .../src/tools/type_tool/canvas_tests.rs | 4 +- .../ui-egui/src/tools/type_tool/defaults.rs | 9 +- crates/ui-egui/src/tools/type_tool/pointer.rs | 55 +++++++++--- crates/ui-egui/src/tools/type_tool/tests.rs | 2 +- 7 files changed, 159 insertions(+), 34 deletions(-) diff --git a/crates/ui-egui/src/dialogs/paragraph_text_size.rs b/crates/ui-egui/src/dialogs/paragraph_text_size.rs index 43dc174947c..7e29c0908da 100644 --- a/crates/ui-egui/src/dialogs/paragraph_text_size.rs +++ b/crates/ui-egui/src/dialogs/paragraph_text_size.rs @@ -11,8 +11,11 @@ //! rectangle between the two points), and Cancel beyond closing the dialog is not specified. //! //! The dialog is a hosted parameter dialog with a key of its own, so `ui.inspect`, `ui.dialog.set` -//! and `ui.dialog.confirm` drive it like the other parameter dialogs. The drag's top-left and the -//! document it was made in are not fields: they are the family's captured value, read by [`run`]. +//! and `ui.dialog.confirm` drive it like the other parameter dialogs. The drag's top-left, the +//! document it was made in and the tool, type options and placeholder preference the new layer is +//! built from are not fields: they are the family's captured value, read by [`run`]. The last of +//! those three is taken when the dialog opens rather than at OK, because the reference application's +//! dialog is modal — the layer keeps what was active at the drag (#12044). use craft::ui::dialog::DialogId; use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, Param, ParamDialog, ParamResult}; @@ -43,13 +46,20 @@ fn build(w: f64, h: f64) -> impl for<'b> Fn(&'b mut DialogFields) -> ParamDialog } /// Open the dialog on the box an Alt+drag drew: top-left `(x, y)`, size `w` × `h`, in document -/// pixels and exactly as dragged (the fields keep the decimals). The top-left and the document the -/// drag was made in are captured for [`run`]: OK creates the text only while that document is -/// still the active one. +/// pixels and exactly as dragged (the fields keep the decimals). The top-left, the document the drag +/// was made in and the settings the new layer is built from are captured for [`run`]: OK creates the +/// text only while that document is still the active one, and with the tool and options that were +/// active at the drag. +/// +/// The settings are snapshotted here rather than read at OK because the reference application's +/// dialog is modal: nothing can change the tool (horizontal or vertical) or its options between the +/// Alt+drag and OK, so the box always uses what was active at the drag. A control that changes them +/// while the dialog happens to be open therefore cannot leak into the new layer (#12044). pub fn open(app: &mut PhotocraftApp, at: [f64; 2], w: f64, h: f64) -> DialogId { let captured = json!({ "at": [at[0], at[1]], "document": app.session.active().map(|st| json!(st.doc.id)).unwrap_or(Value::Null), + "settings": crate::type_tool::TypeSnapshot::live(app), }); let fields = DialogFields::from_pairs([(WIDTH, FieldValue::Number(w)), (HEIGHT, FieldValue::Number(h))]); params::open_param_unsaved(app, KEY, fields, captured, build(w, h)) @@ -73,10 +83,17 @@ pub fn run(app: &mut PhotocraftApp, ctx: &egui::Context, result: ParamResult) { crate::dialogs::alerts::report_error(app, "the Paragraph Text Size dialog has no size"); return; }; - let mut p = crate::type_tool::create_params(app); + // The settings are the ones the drag had, not the ones the app has now: the reference dialog is + // modal, so a control that switched the tool or edited the options while it was open has no say + // in this layer (#12044). + let Ok(settings) = serde_json::from_value(captured.get("settings").cloned().unwrap_or(Value::Null)) else { + crate::dialogs::alerts::report_error(app, "the Paragraph Text Size dialog has no settings snapshot"); + return; + }; + let mut p = crate::type_tool::create_params(app, true, &settings); p["box"] = json!([x, y, w, h]); // A refused create already said why in the status bar, as the gesture's own create does. - if crate::type_tool::create_layer(app, p, None).is_ok() { + if crate::type_tool::create_layer(app, p, None, &settings).is_ok() { crate::type_tool::focus_editor(ctx); } } diff --git a/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs b/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs index 5b2fed9b02d..475d1716d9c 100644 --- a/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs +++ b/crates/ui-egui/src/dialogs/paragraph_text_size/tests.rs @@ -4,7 +4,8 @@ //! route are checked to keep today's behaviour: a plain drag still makes the box directly, Alt+click //! is still point text, the vertical Type tool keeps its plain drag, ⌥ is read at the press so it can //! come up or go down mid-drag, a second drag while the dialog is open is swallowed by that dialog, -//! and a name the dialog does not show as a field is refused. +//! the layer keeps the tool, the type options and the placeholder preference that were active when +//! the dialog opened, and a name the dialog does not show as a field is refused. //! //! The gestures go through the canvas pass (`canvas::testing`), the way the released Type tool does //! on the hosted framework: a press with ⌥ held, a move, a release. The dialog is driven the way a @@ -232,16 +233,95 @@ fn an_alt_drag_with_the_vertical_type_tool_still_makes_the_box_directly() { assert_eq!(box_rect(&app, ed.layer), [10.0, 10.0, 100.0, 50.0], "the plain drag's box"); } -/// Guard (pattern 9, no guessing from a name): the drag's top-left and the document it was made in -/// are the family's captured value, not fields - a control `set_json_field` for a name the dialog -/// does not show is refused, so the geometry cannot be pushed in through the field map. +/// The point size of the new layer's first run, as `type.create` stored it. +fn size_pt(app: &PhotocraftApp, id: u64) -> f32 { + text(app, id).char_runs().into_iter().next().expect("the new layer has one run").style.size_pt +} + +/// #12044 review: the reference dialog is modal, so nothing can change the tool or its options +/// between the Alt+drag and OK. The dialog therefore snapshots the tool, the type options and the +/// placeholder preference when it opens, and OK creates from that snapshot: a control that switches +/// to the vertical Type tool and changes the size while the dialog is open does not leak into the +/// new layer, which stays horizontal at the size the drag had. +#[test] +fn the_layer_keeps_the_tool_and_options_active_at_the_drag() { + let mut app = app(); + app.ui.tool_options.type_font = "Drag Font".into(); + app.ui.tool_options.type_style = "Regular".into(); + app.ui.tool_options.type_size = 24.0; + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT, Modifiers::ALT); + let (d, _) = only_dialog(&app); + // Change the settings the dialog is about to read, while it is open. + app.ui.tool = Tool::VerticalType; + app.ui.tool_options.type_font = "Later Font".into(); + app.ui.tool_options.type_size = 72.0; + let ctx = app.ctx().clone(); + crate::dialogs::confirm(&mut app, &ctx, d).unwrap(); + let ed = app.ui.text_edit.as_ref().expect("OK starts the edit session, as the drag does"); + let t = text(&app, ed.layer); + assert_eq!(t.orientation, photocraft_doc::text::Orientation::Horizontal, "the tool held at the drag, not the one at OK"); + assert_eq!(size_pt(&app, ed.layer), 24.0, "the size held at the drag, not the one at OK"); + assert_eq!(t.char_runs()[0].style.font_family, "Drag Font", "and the family held at the drag"); + assert_eq!(box_rect(&app, ed.layer), [10.0, 10.0, 99.5, 50.0], "still the box the drag drew"); +} + +/// The same snapshot covers the placeholder preference: turning "Fill new type layers with +/// placeholder text" off while the dialog is open does not leave the new layer empty. +#[test] +fn the_layer_keeps_the_placeholder_preference_active_at_the_drag() { + let mut app = app(); + drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT, Modifiers::ALT); + let (d, _) = only_dialog(&app); + app.session.edit_prefs(|p| p.type_.fill_new_type_layers_with_placeholder = false); + let ctx = app.ctx().clone(); + crate::dialogs::confirm(&mut app, &ctx, d).unwrap(); + let ed = app.ui.text_edit.as_ref().expect("OK starts the edit session, as the drag does"); + assert_eq!(text(&app, ed.layer).text, PLACEHOLDER, "the preference held at the drag, not the one at OK"); + assert_eq!((ed.anchor, ed.caret), (0, PLACEHOLDER.chars().count()), "and its placeholder stays selected"); +} + +/// Not changed by the snapshot: a plain drag reads the tool and its options at the moment it ends. +/// Pinned so the snapshot stays inside the dialog's route. +#[test] +fn a_plain_drag_reads_the_settings_at_its_own_release() { + let mut app = app(); + app.ui.tool = Tool::VerticalType; + app.ui.tool_options.type_font = "Drag Font".into(); + app.ui.tool_options.type_size = 24.0; + drag(&mut app, [10.0, 10.0], [110.0, 60.0], Modifiers::NONE, Modifiers::NONE); + let ed = app.ui.text_edit.as_ref().expect("the drag creates the text at once"); + let t = text(&app, ed.layer); + assert_eq!(t.orientation, photocraft_doc::text::Orientation::Vertical, "the tool in hand at the release"); + assert_eq!(size_pt(&app, ed.layer), 24.0, "and the options in hand at the release"); + assert_eq!(t.char_runs()[0].style.font_family, "Drag Font"); +} + +/// The other unchanged neighbour: a click reads the live settings too, including the placeholder +/// preference as it is at that moment. +#[test] +fn a_click_reads_the_settings_at_its_own_release() { + let mut app = app(); + app.session.edit_prefs(|p| p.type_.fill_new_type_layers_with_placeholder = false); + app.ui.tool_options.type_size = 30.0; + drag(&mut app, [50.0, 100.0], [50.0, 100.0], Modifiers::NONE, Modifiers::NONE); + let ed = app.ui.text_edit.as_ref().expect("the click creates point text"); + let t = text(&app, ed.layer); + assert!(matches!(t.shape, photocraft_doc::text::TextShape::Point), "point text"); + assert_eq!(t.text, "", "the preference as it stands at the click"); + assert_eq!(size_pt(&app, ed.layer), 30.0, "and the options as they stand at the click"); +} + +/// Guard (pattern 9, no guessing from a name): the drag's top-left, the document it was made in and +/// the settings snapshot are the family's captured value, not fields - a control `set_json_field` +/// for a name the dialog does not show is refused, so neither the geometry nor the tool and its +/// options can be pushed in through the field map. #[test] fn a_name_the_dialog_does_not_show_as_a_field_is_refused() { let mut app = app(); drag(&mut app, [10.0, 10.0], [109.5, 60.0], Modifiers::ALT, Modifiers::ALT); let (id, _) = only_dialog(&app); let ctx = app.ctx().clone(); - for field in ["at", "document", "box", "text"] { + for field in ["at", "document", "settings", "box", "text"] { assert!(app.framework.dialogs.set_json_field(&ctx, id, field, json!(1.0)).is_err(), "`{field}` is not a field of this dialog"); } assert_eq!(only_dialog(&app).1["width"].as_f64(), Some(99.5), "and the two real fields keep the dragged size"); diff --git a/crates/ui-egui/src/tools/type_tool.rs b/crates/ui-egui/src/tools/type_tool.rs index c26c8401020..1f39f6da3bd 100644 --- a/crates/ui-egui/src/tools/type_tool.rs +++ b/crates/ui-egui/src/tools/type_tool.rs @@ -54,7 +54,7 @@ pub(crate) use panel::toggle_opentype; pub use panel::{character_panel, type_properties}; #[cfg(test)] pub(crate) use pointer::{PathClick, path_target}; -pub(crate) use pointer::{TypeState, box_shape, create_layer, create_params, drain, tool}; +pub(crate) use pointer::{TypeSnapshot, TypeState, box_shape, create_layer, create_params, drain, tool}; pub(crate) use values::doc_unit; pub const PLACEHOLDER: &str = "Lorem Ipsum"; diff --git a/crates/ui-egui/src/tools/type_tool/canvas_tests.rs b/crates/ui-egui/src/tools/type_tool/canvas_tests.rs index d88505cb7a9..0cd9005cf71 100644 --- a/crates/ui-egui/src/tools/type_tool/canvas_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/canvas_tests.rs @@ -417,7 +417,7 @@ mod panel_defaults { let mut app = new_app(); app.ui.tool_options.type_style_defaults = json!({"tracking": 20, "text": "Injected", "box": [0, 0, 2, 2], "coalesce": "unrelated"}).as_object().unwrap().clone(); - let p = super::super::default_style_params(&app); + let p = super::super::default_style_params(&app, &app.ui.tool_options); assert_eq!(p["tracking"], 20); assert!(p.get("text").is_none() && p.get("box").is_none() && p.get("coalesce").is_none()); app.ui.tool_options.type_style_defaults = json!({ @@ -427,7 +427,7 @@ mod panel_defaults { .as_object() .unwrap() .clone(); - let p = super::super::default_style_params(&app); + let p = super::super::default_style_params(&app, &app.ui.tool_options); for key in ["tracking", "leading", "spaceAfter", "variations", "features"] { assert!(p.get(key).is_none(), "hostile {key} is ignored"); } diff --git a/crates/ui-egui/src/tools/type_tool/defaults.rs b/crates/ui-egui/src/tools/type_tool/defaults.rs index 9477b2e60b0..48b9408096d 100644 --- a/crates/ui-egui/src/tools/type_tool/defaults.rs +++ b/crates/ui-egui/src/tools/type_tool/defaults.rs @@ -59,9 +59,10 @@ pub(super) fn shown_scale(app: &PhotocraftApp) -> f32 { /// The styles a new Type-tool layer will receive. Use the same command parameters for the /// panels and creation so defaults also survive action recording/replay. The older options-bar -/// fields remain authoritative, and text colour continues to follow the foreground colour. -pub(super) fn default_style_params(app: &PhotocraftApp) -> serde_json::Value { - let o = &app.ui.tool_options; +/// fields remain authoritative, and text colour continues to follow the foreground colour. `o` is +/// the options-bar state to read: today's live one for a panel or a plain gesture, a snapshot taken +/// when the Paragraph Text Size dialog opened for its OK (#12044). +pub(super) fn default_style_params(app: &PhotocraftApp, o: &crate::state::ToolOptions) -> serde_json::Value { let mut p = json!({}); // Settings are editable JSON: only recognized formatting keys may reach type.create. // In particular a stray `text`, `box`, or `coalesce` key must not become a create parameter. @@ -149,7 +150,7 @@ fn finite_style_value(value: &serde_json::Value) -> bool { pub(super) fn default_styles(app: &PhotocraftApp) -> (photocraft_doc::text::CharStyle, photocraft_doc::text::ParagraphStyle) { let (mut c, mut para) = app.session.type_defaults.clone().unwrap_or_default(); - let mut p = default_style_params(app); + let mut p = default_style_params(app, &app.ui.tool_options); // The saved panels can appear on the very first frame. Style parsing resolves the named // font through shared(), which waits for the font scan; display the saved names meanwhile, // and let fonts_ready/axis_sliders expose the font controls when try_shared is ready. diff --git a/crates/ui-egui/src/tools/type_tool/pointer.rs b/crates/ui-egui/src/tools/type_tool/pointer.rs index 0875c48b3fa..304ad523eca 100644 --- a/crates/ui-egui/src/tools/type_tool/pointer.rs +++ b/crates/ui-egui/src/tools/type_tool/pointer.rs @@ -215,43 +215,67 @@ fn press_at(app: &mut PhotocraftApp, ctx: &egui::Context, x: f64, y: f64, mods: ToolAction::Done } +/// The settings a `type.create` is built from: the tool in hand (horizontal or vertical, and which +/// Type Mask), the options bar's type settings and the placeholder preference. A plain drag or a +/// click reads them live at its release, through [`TypeSnapshot::live`]. The Paragraph Text Size +/// dialog instead takes the snapshot when it opens and hands it to its OK (#12044): that dialog is +/// modal in the reference application, so nothing can change the tool or its options between the +/// Alt+drag and OK, and the box it makes uses what was active at the drag even when a control +/// changes them while the dialog is open. +#[derive(Clone, serde::Serialize, serde::Deserialize)] +pub(crate) struct TypeSnapshot { + pub tool: crate::state::Tool, + pub options: crate::state::ToolOptions, + pub placeholder: bool, +} + +impl TypeSnapshot { + /// Read from the app as it stands at this moment: today's live reading, what the plain drag and + /// the click create with. + pub(crate) fn live(app: &PhotocraftApp) -> Self { + Self { tool: app.ui.tool, options: app.ui.tool_options.clone(), placeholder: app.session.prefs().type_.fill_new_type_layers_with_placeholder } + } +} + /// The `type.create` parameters a Type-tool gesture ending now starts from: the placeholder or /// empty text, the tool's orientation and the options bar's styles. The caller adds the geometry /// (`box` for a dragged paragraph, `x`/`y` for point text), and [`create_layer`] adds the session's /// `coalesce` key. `is_box` says whether the gesture that ends was a paragraph drag, which #12077's -/// mask style applies only to a click. -pub(crate) fn create_params(app: &PhotocraftApp, is_box: bool) -> serde_json::Value { - let mask = app.ui.tool.is_type_mask(); +/// mask style applies only to a click; `s` names the tool and settings to create with. +pub(crate) fn create_params(app: &PhotocraftApp, is_box: bool, s: &TypeSnapshot) -> serde_json::Value { + let mask = s.tool.is_type_mask(); // Preferences ▸ Type: "Fill new type layers with placeholder text" (on by default). The // Horizontal Type Mask gets the Type tool's placeholder, as Photoshop's does (#12072); the // vertical mask's placeholder is not measured yet, so it keeps starting empty. - let placeholder = app.ui.tool != crate::state::Tool::VerticalTypeMask && app.session.prefs().type_.fill_new_type_layers_with_placeholder; + let placeholder = s.tool != crate::state::Tool::VerticalTypeMask && s.placeholder; let text = if placeholder { PLACEHOLDER } else { "" }; - let mut p = default_style_params(app); + let mut p = default_style_params(app, &s.options); // #12077: the measured case - a click, not a paragraph box, with the Horizontal Type Mask over // a horizontal text layer - starts the mask in that layer's font, style and size, as the // options bar shows them for the layer. The vertical mask and a box drag are not measured in // the issue, so they keep today's tool options. if mask && !is_box - && app.ui.tool == crate::state::Tool::HorizontalTypeMask + && s.tool == crate::state::Tool::HorizontalTypeMask && let Some(style) = mask_style_from_active_layer(app) && let (Some(params), Some(style)) = (p.as_object_mut(), style.as_object()) { params.extend(style.clone()); } p["text"] = json!(text); - p["orientation"] = json!(if app.ui.tool.is_vertical_type() { "vertical" } else { "horizontal" }); + p["orientation"] = json!(if s.tool.is_vertical_type() { "vertical" } else { "horizontal" }); p } /// Create the type layer `p` describes, and finish what a released Type-tool gesture does with it: /// the path target of a click, the options bar's antialiasing, the Type Mask tools' hidden working -/// layer, and the edit session with the placeholder selected. The id of the new layer, or why -/// creating it failed (the status bar already says so, since [`PhotocraftApp::run`] reported it). -pub(crate) fn create_layer(app: &mut PhotocraftApp, mut p: serde_json::Value, target: Option) -> Result { - let o = app.ui.tool_options.clone(); - let mask = app.ui.tool.is_type_mask(); +/// layer, and the edit session with the placeholder selected. `s` is the snapshot `p` was built +/// from, so the antialiasing and the Type Mask handling follow those settings and not the live ones. +/// The id of the new layer, or why creating it failed (the status bar already says so, since +/// [`PhotocraftApp::run`] reported it). +pub(crate) fn create_layer(app: &mut PhotocraftApp, mut p: serde_json::Value, target: Option, s: &TypeSnapshot) -> Result { + let o = &s.options; + let mask = s.tool.is_type_mask(); let n = p.get("text").and_then(serde_json::Value::as_str).unwrap_or("").chars().count(); let key = session_key(app); p["coalesce"] = json!(key); @@ -303,14 +327,17 @@ fn create_text(app: &mut PhotocraftApp, start: [f64; 2], end: [f64; 2], alt_at_p // A click (not a drag) with the Type tool on a path: area type inside a closed path, type // on the path on its outline. The Type Mask tools ignore paths. let target = if !mask && !is_box { path_target(app, start[0], start[1]) } else { None }; - let mut p = create_params(app, is_box); + // A plain drag or click reads the tool, its options and the placeholder preference as they + // stand at its release, as they always have (#12044). + let snapshot = TypeSnapshot::live(app); + let mut p = create_params(app, is_box, &snapshot); if is_box { p["box"] = json!([start[0].min(end[0]).round(), start[1].min(end[1]).round(), w.round(), h.round()]); } else { p["x"] = json!(start[0].round()); p["y"] = json!(start[1].round()); } - let _ = create_layer(app, p, target); + let _ = create_layer(app, p, target, &snapshot); } impl CanvasTool for TypeTool<'_> { diff --git a/crates/ui-egui/src/tools/type_tool/tests.rs b/crates/ui-egui/src/tools/type_tool/tests.rs index 35adeb9e3da..f0a254b9507 100644 --- a/crates/ui-egui/src/tools/type_tool/tests.rs +++ b/crates/ui-egui/src/tools/type_tool/tests.rs @@ -56,7 +56,7 @@ fn layer_text(app: &PhotocraftApp) -> String { fn stacked_variant(app: &mut PhotocraftApp, s: &str) -> LayerId { // A click on the stack's spot would edit the text under it, so the layer is made where the click would. app.ui.text_edit = None; - let mut p = default_style_params(app); + let mut p = default_style_params(app, &app.ui.tool_options); p["text"] = json!(s); p["orientation"] = json!("horizontal"); p["x"] = json!(50.0);