PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Color: the Move tool recolours the selected type and shapes too
bazmarth62ab7f38685f
diff --git a/crates/ui-egui/src/apply_color.rs b/crates/ui-egui/src/apply_color.rsindex ce51b23fe..ed40823a0 100644--- a/crates/ui-egui/src/apply_color.rs+++ b/crates/ui-egui/src/apply_color.rs@@ -1,12 +1,14 @@-//! A new foreground colour recolours the selected objects, as in Photoshop: the Color panel, the-//! Swatches panel and the Color Picker set the foreground, and depending on the tool in hand it-//! also goes to what is selected:+//! A new foreground colour recolours the selected objects: the Color panel, the Swatches panel and+//! the Color Picker set the foreground, and depending on the tool in hand it also goes to what is+//! selected://!//! * characters selected while editing type: those characters (`type_tool::foreground_changed`);//! * a Type tool, not editing: the colour of every selected type layer (`type.setStyle`);//! * a shape tool, a Pen or a path selection tool: the fill of every selected shape layer//! (`shape.edit` with `fill`);-//! * any other tool (Move, the brushes…): nothing, only the foreground changes.+//! * the Move tool (layers picked by a click, ⇧-click or its marquee): both, every selected type+//! layer and shape;+//! * any other tool (the brushes, the pixel selection tools…): nothing, only the foreground.//!//! One pick is one history step for all the layers it recolours; a drag in the Color panel's field//! or sliders is one step too.@@ -55,18 +57,22 @@ pub fn foreground_changed(app: &mut PhotocraftApp, continuing: bool) {return;}let tool = app.ui.tool;- let type_tool = tool.is_type() && !tool.is_type_mask();- if !type_tool && !recolours_shapes(tool) {- return;- }+ // What the tool in hand recolours: type layers, shape layers, or both (the Move tool).+ let (do_texts, do_shapes) = match tool {+ Tool::Move => (true, true),+ t if t.is_type() && !t.is_type_mask() => (true, false),+ t if recolours_shapes(t) => (false, true),+ _ => return,+ };let Some(st) = app.session.active() else { return };let (texts, shapes): (Vec<u64>, Vec<u64>) = {let selected: Vec<_> = st.selected_layers().into_iter().filter_map(|id| st.doc.layer(id)).collect();let pick = |want: fn(&LayerContent) -> bool| selected.iter().filter(|l| want(&l.content)).map(|l| l.id.0).collect::<Vec<_>>();(pick(|c| matches!(c, LayerContent::Text(_))), pick(|c| matches!(c, LayerContent::Shape(_))))};- let targets = if type_tool { &texts } else { &shapes };- if targets.is_empty() {+ let texts = if do_texts { texts } else { Vec::new() };+ let shapes = if do_shapes { shapes } else { Vec::new() };+ if texts.is_empty() && shapes.is_empty() {return;}let key = match app.ui.apply_color_key.clone().filter(|_| continuing) {@@ -78,11 +84,12 @@ pub fn foreground_changed(app: &mut PhotocraftApp, continuing: bool) {}};let color = hex(app.session.tools.foreground);- let result = if type_tool {- app.run("type.setStyle", json!({"layers": texts, "color": color, "coalesce": key})).map(|_| ())- } else {+ let result = (|| {+ if !texts.is_empty() {+ app.run("type.setStyle", json!({"layers": texts, "color": color, "coalesce": key}))?;+ }shapes.iter().try_for_each(|id| app.run("shape.edit", json!({"layer": id, "fill": color, "coalesce": key})).map(|_| ()))- };+ })();if let Err(e) = result {app.ui.status = e;app.ui.status_error = true;diff --git a/crates/ui-egui/src/apply_color_tests.rs b/crates/ui-egui/src/apply_color_tests.rsindex 0a0accb6b..a007eb984 100644--- a/crates/ui-egui/src/apply_color_tests.rs+++ b/crates/ui-egui/src/apply_color_tests.rs@@ -91,7 +91,7 @@ fn shape_and_path_tools_recolour_every_selected_shape_fill_in_one_step() {#[test]fn other_tools_only_change_the_foreground() {- for tool in [Tool::Move, Tool::Brush, Tool::RectMarquee, Tool::Eyedropper, Tool::HorizontalTypeMask] {+ for tool in [Tool::Brush, Tool::RectMarquee, Tool::Eyedropper, Tool::HorizontalTypeMask] {let (mut app, texts, shapes) = app(tool);let n = steps(&app);pick(&mut app, RED, false);@@ -142,3 +142,43 @@ fn a_swatch_and_the_color_picker_go_through_it() {assert_eq!(app.session.tools.foreground, [0.0, 0.0, 1.0, 1.0]);assert!(shapes.iter().all(|id| same(&app, *id)), "the picker recoloured the shapes");}++#[test]+fn the_move_tool_recolours_the_selected_type_and_shapes_together_in_one_step() {+ // Layers picked with the Move tool (a click, ⇧-click or its marquee) take the colour, type and+ // shapes alike.+ let (mut app, texts, shapes) = app(Tool::Move);+ let n = steps(&app);+ pick(&mut app, RED, false);+ assert!(texts.iter().all(|id| red(text_rgb(&app, *id))), "the type is red");+ assert!(shapes.iter().all(|id| fill_rgb(&app, *id).is_some_and(red)), "the shapes are red");+ assert_eq!(steps(&app), n + 1, "one history step for all four layers");+ assert!(app.session.undo());+ assert!(texts.iter().all(|id| !red(text_rgb(&app, *id))) && shapes.iter().all(|id| !red(fill_rgb(&app, *id).unwrap())));+ // Only the selected ones: with one shape selected, the rest keep their colour.+ app.run("layer.select", json!({"layer": shapes[0].0})).unwrap();+ pick(&mut app, RED, false);+ assert!(fill_rgb(&app, shapes[0]).is_some_and(red));+ assert!(!red(fill_rgb(&app, shapes[1]).unwrap()) && texts.iter().all(|id| !red(text_rgb(&app, *id))));+}++#[test]+fn a_move_tool_marquee_selection_takes_the_colour() {+ // The video case: shapes box-selected with the Move tool's marquee, then a swatch.+ let (mut app, _, shapes) = app(Tool::Move);+ app.run("layer.select", json!({"layer": shapes[0].0})).unwrap();+ // The marquee from an empty spot across both shapes.+ for (kind, x, y) in [("down", 140.0, 10.0), ("move", 200.0, 50.0), ("move", 290.0, 90.0), ("up", 290.0, 90.0)] {+ let ev = match kind {+ "down" => crate::canvas::ToolEvent::Down { x, y, pressure: 1.0 },+ "move" => crate::canvas::ToolEvent::Move { x, y, pressure: 1.0 },+ _ => crate::canvas::ToolEvent::Up { x, y },+ };+ crate::canvas::tool_event(&mut app, ev, egui::Modifiers::NONE);+ }+ let mut sel = app.session.active().unwrap().selected_layers();+ sel.sort_by_key(|l| l.0);+ assert_eq!(sel, shapes, "the marquee selected both shapes");+ pick(&mut app, RED, false);+ assert!(shapes.iter().all(|id| fill_rgb(&app, *id).is_some_and(red)));+}diff --git a/docs/ui-parity.md b/docs/ui-parity.mdindex e22aee348..adb6c2da4 100644--- a/docs/ui-parity.md+++ b/docs/ui-parity.md@@ -207,7 +207,7 @@ Paragraph; the rest open as in-app floating windows.| Drag panels to reorder and regroup | partial | #2272, #2305 || Docked resize pushes the neighbour | partial | #2573 || Color panel wheel and RGB/HSB/CMYK/Lab sliders | missing | UI-217-17, #2569 |-| A colour picked in the Color or Swatches panel or the Color Picker recolours the selection: selected characters while editing; every selected type layer with a Type tool; every selected shape's fill with a shape, Pen or path selection tool; only the foreground with other tools; one history step (a Color panel drag too) | done: `apply_color.rs`, `apply_color_tests.rs` | |+| A colour picked in the Color or Swatches panel or the Color Picker recolours the selection: selected characters while editing; every selected type layer with a Type tool; every selected shape's fill with a shape, Pen or path selection tool; both with the Move tool (layers picked by click, ⇧-click or its marquee); only the foreground with other tools; one history step (a Color panel drag too) | done: `apply_color.rs`, `apply_color_tests.rs` | || Window size and dock width remembered | done | UI-217-2 || Command palette with recents | done | UI-217-7 || Menu bar from the keyboard: Alt / F10 focus the bar, ← → ↓ ↩ drive it, Alt+letter opens a menu, underlined mnemonics run items | done | `menu_keys.rs`, #4988; macOS uses the native bar |@@ -254,4 +254,4 @@ Paragraph; the rest open as in-app floating windows.| 2026-10-11 | minor | Pen ⇧ 45° done: ⇧-click puts the next anchor on the nearest 45° ray, ⇧-drag turns its handles in 45° steps (TOOL-214-10 done, #3751) || 2026-10-14 | minor | Last selected tool restored across launches; temporary overrides excluded, explicit Eraser choices retained, and final selection flushed on normal exit || 2026-10-13 | minor | Free Transform with a selection: the box is the selection's rectangle, and the marching ants follow it while it is transformed (#5297) |-| 2026-10-14 | minor | A colour picked in the Color or Swatches panel or the Color Picker recolours the selected type layers (Type tool) or shape fills (shape, Pen and path selection tools) |+| 2026-10-14 | minor | A colour picked in the Color or Swatches panel or the Color Picker recolours the selected type layers (Type tool), shape fills (shape, Pen and path selection tools), or both (Move tool) |