diff --git a/crates/ui-egui/src/panels/swatches/dnd.rs b/crates/ui-egui/src/panels/swatches/dnd.rs index 5a1a04484f..5cf2d06b23 100644 --- a/crates/ui-egui/src/panels/swatches/dnd.rs +++ b/crates/ui-egui/src/panels/swatches/dnd.rs @@ -183,7 +183,8 @@ fn tile_drop(ui: &Ui, resp: &Response, e: &Entry, list: bool, ev: &mut TileEvent ui.painter().line_segment([pos2(x, r.top() - 1.0), pos2(x, r.bottom() + 1.0)], Stroke::new(2.0, t.accent)); } if resp.dnd_release_payload::().is_some() { - ev.drop = Drop::of(&d, Some(name.to_string()), after, crate::panels::alt_held(ui), command_held(ui)); + let m = release_modifiers(ui); + ev.drop = Drop::of(&d, Some(name.to_string()), after, m.alt, m.command); } } @@ -195,13 +196,23 @@ pub(super) fn zone_input(ui: &Ui, zone: &Response, ev: &mut TileEvents) { ui.painter().rect_stroke(zone.rect, 0.0, Stroke::new(1.5, Tokens::get(ui.ctx()).accent), StrokeKind::Inside); } if zone.dnd_release_payload::().is_some() { - ev.drop = Drop::of(&d, None, false, false, command_held(ui)); + ev.drop = Drop::of(&d, None, false, false, release_modifiers(ui).command); } } -/// Is Cmd (macOS) or Ctrl (Windows, Linux) held? -fn command_held(ui: &Ui) -> bool { - ui.input(|i| i.modifiers.command) +/// The modifiers (Alt; Cmd on macOS, Ctrl on Windows and Linux) held when the primary button was +/// released this frame, as the release event carries them, so a key let go later in the same frame +/// does not change the drop. Without such an event, the modifiers held at the end of the frame. +fn release_modifiers(ui: &Ui) -> egui::Modifiers { + ui.input(|i| { + i.events + .iter() + .find_map(|e| match e { + egui::Event::PointerButton { button: egui::PointerButton::Primary, pressed: false, modifiers, .. } => Some(*modifiers), + _ => None, + }) + .unwrap_or(i.modifiers) + }) } /// The colour group `name` is, or the one swatch `name` belongs to. @@ -271,7 +282,8 @@ fn shown_color_params(paint: &Paint) -> Value { /// Run a drop on the panel: move the swatches, give the paint of a swatch Alt-dropped on another of /// its kind to that one, or make a swatch of the proxy's paint (a color dropped on a folder or a /// grouped swatch joins that group; a color Cmd/Ctrl-dropped becomes a new spot color of the color -/// the drag shows, tints included). +/// the drag shows, tints included). With Alt also held, a color dropped on a swatch it can replace +/// replaces that swatch's color with the color the drag shows and makes no spot color. pub(super) fn apply_drop(app: &mut VectorcraftApp, drop: Drop) { let Some(d) = app.session.active().map(|st| &st.doc) else { return }; let (cmd, params) = match drop { @@ -282,11 +294,13 @@ pub(super) fn apply_drop(app: &mut VectorcraftApp, drop: Drop) { Some(p) => ("swatch.move", p), None => return, }, - // Alt: an edited gradient (or colour) replaces the swatch it is dropped on. - Drop::New { paint, target: Some(t), replace: true, .. } + // Alt: an edited gradient (or colour) replaces the swatch it is dropped on. With Cmd/Ctrl also + // held, a tint gives the color the drag shows; Alt alone sends the paint as it is. + Drop::New { paint, target: Some(t), replace: true, spot } if d.swatch(&t).is_some_and(|w| !w.is_reserved() && w.tint_of().is_none() && same_kind(&w.paint, &paint)) => { - ("swatch.edit", json!({"name": t, "paint": shown_color_params(&paint)})) + let p = if spot { shown_color_params(&paint) } else { crate::panels::swatch_paint_params(&paint) }; + ("swatch.edit", json!({"name": t, "paint": p})) } Drop::New { paint, target, spot, .. } => { // Only a spot color needs a color of its own; other drops keep a tint's link to its base. diff --git a/crates/ui-egui/src/panels/swatches/tests.rs b/crates/ui-egui/src/panels/swatches/tests.rs index 8b2cf783ca..ea466f4252 100644 --- a/crates/ui-egui/src/panels/swatches/tests.rs +++ b/crates/ui-egui/src/panels/swatches/tests.rs @@ -1305,6 +1305,51 @@ fn a_tint_alt_dropped_on_a_swatch_replaces_it_with_the_captured_color() { assert_eq!(red.paint.color(), Some(shown), "{}", app.ui.status); } +/// A tint Alt-dropped on a solid swatch without Cmd/Ctrl sends the tint as it is, so the swatch takes +/// the tint of its base swatch as the base is at the drop. +#[test] +fn a_tint_alt_dropped_without_cmd_keeps_the_tint_paint() { + let mut app = app(); + let ctx = context(); + app.run("swatch.edit", json!({"name": "Orange", "global": true})).unwrap(); + app.run("swatch.new", json!({"swatch": "Orange", "tint": 40})).unwrap(); + let tint = app.session.doc().unwrap().doc.tint_paint("Orange", 0.4).expect("a tint of Orange"); + let shown = tint.color().expect("a color"); + app.run("swatch.edit", json!({"name": "Orange", "paint": {"color": "#2040c0"}})).unwrap(); + let now = app.session.doc().unwrap().doc.tint_paint("Orange", 0.4).and_then(|p| p.color()).expect("a tint of Orange"); + assert_ne!(now, shown); + drop_paint_on(&mut app, &ctx, "Red", tint, Modifiers::ALT, 1.0); + let red = app.session.doc().unwrap().doc.swatch("Red").cloned().expect("Red"); + assert_eq!(red.paint.color(), Some(now), "{}", app.ui.status); +} + +/// A drop on the list follows the modifiers the release carries, not the ones held at the end of the +/// frame: Cmd/Ctrl let go after the release still makes a spot color, Cmd/Ctrl pressed after it does +/// not, and Alt let go after the release still replaces the swatch. +#[test] +fn a_drop_follows_the_modifiers_of_its_release() { + let mut app = app(); + let ctx = context(); + frame(&mut app, &ctx, vec![], 0.0, show); + let at = tile_center(&ctx, "Red"); + let drop = |app: &mut VectorcraftApp, color: &str, held: Modifiers, after: Modifiers, time: f64| { + egui::DragAndDrop::set_payload(&ctx, PanelDrag::paint(Paint::solid(Color::from_hex(color).unwrap()))); + let release = Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: false, modifiers: held }; + frame_with(app, &ctx, vec![Event::PointerMoved(at), release, Event::ModifiersChanged(after)], held, time, show); + }; + let spots = spot_count(&app); + drop(&mut app, "#30a050", Modifiers::COMMAND, Modifiers::NONE, 1.0); + assert_eq!(spot_count(&app), spots + 1, "Cmd/Ctrl held at the release: {}", app.ui.status); + let count = app.session.doc().unwrap().doc.swatches_iter().count(); + drop(&mut app, "#50a030", Modifiers::NONE, Modifiers::COMMAND, 2.0); + let d = &app.session.doc().unwrap().doc; + assert_eq!((d.swatches_iter().count(), spot_count(&app)), (count + 1, spots + 1), "{}", app.ui.status); + drop(&mut app, "#2040c0", Modifiers::ALT, Modifiers::NONE, 3.0); + let d = &app.session.doc().unwrap().doc; + assert_eq!(d.swatches_iter().count(), count + 1, "Alt held at the release adds no swatch: {}", app.ui.status); + assert_eq!(d.swatch("Red").and_then(|w| w.paint.color()), Color::from_hex("#2040c0")); +} + /// A Recent Colors chip of the Color panel dragged onto the Swatches panel becomes a swatch; a click /// on it still paints the selected art. #[test] diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index c7ea6a9387..c7d87bb1ba 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1853,7 +1853,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur Unchecking Show Recent Colors in the Color panel's menu hides its Recent Colors row, and checking it shows the row again ([Select colors using the Color panel](https://helpx.adobe.com/illustrator/desktop/manage-colors/select-and-adjust-colors/select-colors-using-the-color-panel.html)). In VectorCraft the item is checked by default and kept between sessions, applied colors still join the list while the row is hidden, Hide Options hides the row either way, and the Swatches panel keeps its row (`ui.colorPanel {recentColors}`). Tests: `show_recent_colors_hides_and_shows_the_row` in `crates/ui-egui/src/panels/color/tests.rs`. The Swatches panel's menu has its own Show Recent Colors item: unchecking it hides the panel's Recent Colors row and checking it shows the row again ([Color Enhancements in Illustrator](https://community.adobe.com/announcements-651/color-enhancements-in-illustrator-816797) puts recent colors in the Color and Swatches panels; [Select colors using the Color panel](https://helpx.adobe.com/illustrator/desktop/manage-colors/select-and-adjust-colors/select-colors-using-the-color-panel.html) hides them with Show Recent Colors in the panel menu; a [community thread](https://community.adobe.com/questions-652/swatches-disappear-in-swatches-panel-when-switching-between-documents-in-29-7-1-on-macos-816823) turns it off from the Swatches panel). In VectorCraft it is checked by default, kept between sessions apart from the Color panel's, and applied colors still join the list while the row is hidden (#6617). Tests: `show_recent_colors_hides_and_shows_the_swatches_row` in `crates/ui-egui/src/panels/swatches/tests.rs`. A Recent Colors chip in the Color or Swatches panel drags into the Swatches panel's list to become a swatch of its color, in its color model, as one undo step ([Select colors using the Color panel](https://helpx.adobe.com/illustrator/desktop/manage-colors/select-and-adjust-colors/select-colors-using-the-color-panel.html)). In VectorCraft a chip dropped on a color group or one of its swatches joins that group, anywhere else in the list it joins the ungrouped swatches at the end, a color that is already a swatch is added again under another name, and dragging a chip does not paint the selected art (`swatch.new`). Tests: `a_recent_color_dragged_onto_the_list_becomes_a_swatch` and `a_recent_color_dragged_from_the_color_panel_becomes_a_swatch` in `crates/ui-egui/src/panels/swatches/tests.rs`. - A color dragged into the Swatches panel with Cmd (macOS) or Ctrl (Windows) held becomes a spot color swatch ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-colors/use-swatches/create-spot-color-swatches.html) gives this drag from the Color panel as one way to make a spot color). VectorCraft's own rules: Ctrl works on Linux too, and the modifier is read on release; the Fill and Stroke squares, Recent Colors chips and Color Guide colors drag the same way; the new swatch is global, keeps the dragged color's model, joins the color group it is dropped on (anywhere else, the ungrouped swatches at the end), takes a name of its own and is one undo step that paints no art; a tint dragged this way becomes a new spot color of the tinted color, and its base swatch stays as it is; a drop uses the color the drag showed, also when the tint's base swatch changes before the release; with Alt also held, a color dropped on a solid swatch replaces it, and one dropped on Registration or a tint swatch becomes a spot color; gradients, patterns, Registration and swatches dragged within the panel are not made spot colors (`swatch.new {spot: true}`). Tests: `a_color_cmd_dropped_on_the_panel_becomes_a_spot_swatch`, `a_color_cmd_dropped_on_empty_list_space_becomes_a_spot_swatch`, `a_cmd_drop_of_other_paints_or_rows_makes_no_spot_color`, `cmd_drops_of_tints_and_with_alt_follow_the_replacement_rule`, `a_cmd_dropped_tint_makes_its_spot_from_the_captured_color` and `a_tint_alt_dropped_on_a_swatch_replaces_it_with_the_captured_color` in `crates/ui-egui/src/panels/swatches/tests.rs`. + A color dragged into the Swatches panel with Cmd (macOS) or Ctrl (Windows) held becomes a spot color swatch ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-colors/use-swatches/create-spot-color-swatches.html) gives this drag from the Color panel as one way to make a spot color). VectorCraft's own rules: Ctrl works on Linux too, and Cmd/Ctrl and Alt are read from the release itself, so a key let go in the same frame after the release does not change the drop; the Fill and Stroke squares, Recent Colors chips and Color Guide colors drag the same way; the new swatch is global, keeps the dragged color's model, joins the color group it is dropped on (anywhere else, the ungrouped swatches at the end), takes a name of its own and is one undo step that paints no art; a tint dragged this way becomes a new spot color of the tinted color, and its base swatch stays as it is; a drop uses the color the drag showed, also when the tint's base swatch changes before the release; with Alt also held, a color dropped on a solid swatch replaces it with the color the drag showed and makes no spot color, and one dropped on Registration or a tint swatch becomes a spot color; Alt without Cmd/Ctrl replaces a solid swatch with a dragged tint as before, taking the tint of its base swatch as the base is at the release; gradients, patterns, Registration and swatches dragged within the panel are not made spot colors (`swatch.new {spot: true}`). Tests: `a_color_cmd_dropped_on_the_panel_becomes_a_spot_swatch`, `a_color_cmd_dropped_on_empty_list_space_becomes_a_spot_swatch`, `a_cmd_drop_of_other_paints_or_rows_makes_no_spot_color`, `cmd_drops_of_tints_and_with_alt_follow_the_replacement_rule`, `a_cmd_dropped_tint_makes_its_spot_from_the_captured_color`, `a_tint_alt_dropped_on_a_swatch_replaces_it_with_the_captured_color`, `a_tint_alt_dropped_without_cmd_keeps_the_tint_paint` and `a_drop_follows_the_modifiers_of_its_release` in `crates/ui-egui/src/panels/swatches/tests.rs`. A Cmd/Ctrl-click on the Color panel's spectrum applies Complement and a Cmd/Ctrl+Shift-click applies Invert to the active Fill or Stroke (`paint.complement`, `paint.invert`); with Alt also held, the click recolors the inactive one, as the reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) list them. The Color panel spectrum grows into the vertical space of a resized panel, with Show Options or Hide Options (#8005); compact auto-fit flyouts and embedded mixers retain their previous height. Regression: panels::color::tests::the_spectrum_grows_with_the_color_panel. Scores and estimates unchanged. A double-click right of an RGB field switches the Color panel's R, G and B between percent and 0 to 255 ([Default keyboard shortcuts](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html), Color panel). In VectorCraft the color does not change, Web Safe RGB and the hex field stay in 0 to 255, and the panel keeps the choice between sessions (`ui.colorPanel {rgbPercent}`); the color mixer of the Fill and Stroke chips and the gradient stop dialog follow the same setting. Toggle RGB Percent (`ui.colorRgbPercent`) in the command palette and Keyboard Shortcuts switches the units from the keyboard. Tests: `rgb_percent_switches_the_rgb_fields_between_percent_and_0_to_255`, `rgb_percent_does_not_switch_while_the_rows_are_disabled`, `rgb_percent_comes_back_after_a_restart` and `toggle_rgb_percent_switches_the_units_from_the_keyboard` in `crates/ui-egui/src/panels/color/tests.rs`.