PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Type move zone: leave the paragraph box to the caret (#7606)
Hector Villarrealb960c3a4e2fa
diff --git a/crates/ui-egui/src/type_tool.rs b/crates/ui-egui/src/type_tool.rsindex ee29a9e1d..7d9fc3039 100644--- a/crates/ui-egui/src/type_tool.rs+++ b/crates/ui-egui/src/type_tool.rs@@ -239,7 +239,7 @@ fn resize_box(app: &mut PhotocraftApp, ed: &TextEdit, i: u8, x: f64, y: f64) {/// True when document point (`x`, `y`) lies inside the paragraph box of type layer `id` (false/// for point text).-fn inside_box(app: &mut PhotocraftApp, id: LayerId, x: f64, y: f64) -> bool {+pub(crate) fn inside_box(app: &mut PhotocraftApp, id: LayerId, x: f64, y: f64) -> bool {let Some((bx, by, w, h)) = box_shape(app, id) else { return false };let Some((_, aff, _)) = layout(app, id) else { return false };let (tx, ty) = to_text(&aff, x, y);diff --git a/crates/ui-egui/src/type_transform.rs b/crates/ui-egui/src/type_transform.rsindex 51ae9a608..0a48d8449 100644--- a/crates/ui-egui/src/type_transform.rs+++ b/crates/ui-egui/src/type_transform.rs@@ -19,8 +19,9 @@ const PREVIEW_BASE: u64 = 1 << 37;const ROTATE_PX: f64 = 28.0;/// How far outside the text being typed a plain press moves it, as the Move tool (#5956), in/// screen points. Photoshop 2025, measured at 100 %: a drag from 35 pt off the glyphs moved the-/// text without ending typing, one from 48 pt committed it instead.-const MOVE_REACH_PT: f64 = 40.0;+/// text without ending typing, one from 48 pt committed it instead. Kept under 40 pt, so a press+/// 40 pt outside a paragraph box still commits the text (#7606).+const MOVE_REACH_PT: f64 = 38.0;/// Cached rendered preview and bounded damage history. Unchanged pointer positions render nothing.pub(crate) struct Preview {@@ -180,6 +181,10 @@ fn move_zone(app: &mut PhotocraftApp, p: [f64; 2]) -> Option<TransformSession> {if crate::transform_tool::hit(&t, p, 0.0) != Hit::Outside || border_points(app, &t, p) > MOVE_REACH_PT {return None;}+ // Inside a paragraph box, off the glyphs, a press places the caret, as in Photoshop (#7606).+ if crate::type_tool::inside_box(app, LayerId(t.layer), p[0], p[1]) {+ return None;+ }let other = crate::type_tool::hit_layer(app, p[0], p[1]).is_some_and(|id| id.0 != t.layer);(!other).then_some(t)}