Merge pull request #8043 from dotCooCoo/fix/issue-8024

Eyedropper: Escape ends a gradient stop's or Key Color's pick and returns to the previous tool
This commit is contained in:
BFlat
2026-11-17 08:20:01 +07:00
committed by GitHub
5 changed files with 128 additions and 1 deletions
+71 -1
View File
@@ -16,6 +16,9 @@
//!
//! Brush Options' Key Color eyedropper sets `brushKeyColor` and `stop`: the next click samples into
//! the open dialog (`brushKeyColor` UI request) and switches back.
//!
//! Escape ends either pick without sampling and switches back to that tool. With neither pick
//! armed, Escape is left to the application.
use std::collections::HashSet;
@@ -28,7 +31,7 @@ use vectorcraft_geom::{Affine, Point, Rect};
use super::paint_owner;
use crate::params::color_json;
use crate::{Action, Cursor, Mods, Overlay, PointerEvent, PointerKind, Tool, ToolContext};
use crate::{Action, Cursor, Mods, Overlay, PointerEvent, PointerKind, Tool, ToolContext, ToolKey};
#[derive(Default)]
pub struct EyedropperTool {
@@ -530,6 +533,38 @@ impl Tool for EyedropperTool {
fn cursor(&self, _cx: &ToolContext, _p: Point, _m: Mods) -> Cursor {
Cursor::Eyedropper
}
/// Escape ends a gradient stop's or Key Color's pick without sampling and switches back to the
/// tool that armed it.
fn key(&mut self, _cx: &ToolContext, key: ToolKey, _mods: Mods) -> Vec<Action> {
if key != ToolKey::Escape || !self.picking() {
return vec![];
}
let back = self.stop.take().unwrap_or_else(|| "selection".to_string());
self.brush_key_color = false;
vec![Action::SwitchTool(back)]
}
/// A dropped press (a long or canceled touch) leaves an armed pick waiting for its click.
fn drop_press(&mut self, _cx: &ToolContext) -> Vec<Action> {
vec![]
}
/// Escape is the tool's while a pick is armed, so it switches back and ends nothing else.
fn claims_key(&self, _cx: &ToolContext, key: ToolKey) -> bool {
key == ToolKey::Escape && self.picking()
}
fn ends_on_escape(&self, _cx: &ToolContext) -> bool {
self.picking()
}
}
impl EyedropperTool {
/// Is a one-shot pick armed (a gradient stop's or Brush Options' Key Color)?
fn picking(&self) -> bool {
self.stop.is_some() || self.brush_key_color
}
}
#[cfg(test)]
@@ -619,6 +654,41 @@ mod tests {
assert_eq!(t.options(), json!({"stop": null, "brushKeyColor": false}), "one sample only");
}
/// #8024: Escape ends a gradient stop's pick and a Key Color pick without sampling and
/// switches back; the plain Eyedropper leaves Escape alone.
#[test]
fn escape_ends_a_pick_and_switches_back() {
let (d, _) = doc_with_rect();
let (s, p) = (Selection::default(), paint());
let mut cx = cx(&d, &s, &p);
cx.gradient_stop = Some(1);
let none = Mods::default();
let mut t = EyedropperTool::default();
assert!(!t.claims_key(&cx, ToolKey::Escape) && !t.ends_on_escape(&cx), "nothing armed");
assert!(t.key(&cx, ToolKey::Escape, none).is_empty());
t.set_option("stop", &json!("gradient"));
assert!(t.claims_key(&cx, ToolKey::Escape) && t.ends_on_escape(&cx));
assert!(!t.claims_key(&cx, ToolKey::Enter));
assert!(t.drop_press(&cx).is_empty(), "a dropped press leaves the pick armed");
assert_eq!(t.key(&cx, ToolKey::Escape, none), vec![Action::SwitchTool("gradient".into())]);
assert_eq!(t.options(), json!({"stop": null, "brushKeyColor": false}));
assert!(!t.claims_key(&cx, ToolKey::Escape) && t.key(&cx, ToolKey::Escape, none).is_empty(), "one cancel only");
let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, 100.0, 150.0));
assert!(!a.iter().any(|a| matches!(a, Action::Exec(_, v) if v.get("stop").is_some())), "no stop sample after the cancel: {a:?}");
t.set_option("brushKeyColor", &json!(true));
t.set_option("stop", &json!("paintbrush"));
assert!(t.claims_key(&cx, ToolKey::Escape));
assert_eq!(t.key(&cx, ToolKey::Escape, none), vec![Action::SwitchTool("paintbrush".into())]);
assert_eq!(t.options(), json!({"stop": null, "brushKeyColor": false}));
// A Key Color pick with no tool to return to goes back to the Selection tool.
t.set_option("brushKeyColor", &json!(true));
assert_eq!(t.key(&cx, ToolKey::Escape, none), vec![Action::SwitchTool("selection".into())]);
assert_eq!(t.options(), json!({"stop": null, "brushKeyColor": false}));
}
#[test]
fn brush_key_color_samples_into_the_dialog_then_switches_back() {
let (d, _) = doc_with_rect();
@@ -204,6 +204,27 @@ fn brush_key_color_eyedropper_updates_the_open_dialog() {
assert_eq!(app.session.tool_id(), back);
}
/// #8024: the first Escape ends the Key Color pick and returns to the tool that armed it, leaving
/// Brush Options open with its Key Color; a new press then cancels the dialog.
#[test]
fn escape_ends_the_key_color_pick_and_leaves_brush_options_open() {
let (mut app, ctx) = (app(), ctx());
app.select_tool("paintbrush");
app.run("ui.brushOptions", json!({"name": "Confetti"})).unwrap();
set(&mut app, json!({"colorization": "hueShift"}));
let before = app.ui.dialog.as_ref().and_then(|d| d.fields.get("keyColor").cloned());
app.select_tool("eyedropper");
app.session.set_tool_option("brushKeyColor", &json!(true));
app.session.set_tool_option("stop", &json!("paintbrush"));
frame(&ctx, &mut app, vec![], "");
escape(&ctx, &mut app);
assert!(app.ui.dialog.is_some(), "Brush Options stays open");
assert_eq!(app.ui.dialog.as_ref().and_then(|d| d.fields.get("keyColor").cloned()), before, "the Key Color stays");
assert_eq!(app.session.tool_id(), "paintbrush");
escape(&ctx, &mut app);
assert!(app.ui.dialog.is_none(), "a new press cancels Brush Options");
}
#[test]
fn art_options_set_width_scale_direction_flips_and_colorization() {
let mut app = app();
@@ -711,6 +711,27 @@ fn the_stop_eyedropper_arms_the_eyedropper_for_the_stop() {
assert_eq!((app.session.tool_id(), app.session.tool_options()), ("eyedropper", json!({"stop": "gradient", "brushKeyColor": false})));
}
/// #8024: Escape ends the stop eyedropper's pick and returns to the Gradient tool. The stop keeps
/// its color, the selection stays, and a held Escape's repeats end nothing else.
#[test]
fn escape_ends_the_stop_eyedropper_and_returns_to_the_gradient_tool() {
let mut app = app(json!({"gradient": {}}));
crate::shortcut_editor::sync(&app.ui);
app.select_tool("gradient");
app.run("gradient.selectStop", json!({"index": 0})).unwrap();
let (paint, selected) = (current(&app), app.session.active().unwrap().selection.objects.clone());
stop_eyedropper(&mut app);
let key = |pressed, repeat| Event::Key { key: egui::Key::Escape, physical_key: None, pressed, repeat, modifiers: Modifiers::NONE };
let ctx = egui::Context::default();
for events in [vec![key(true, false)], vec![key(true, true)], vec![key(false, false)]] {
let mut out = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| crate::shortcuts::handle(&mut app, ui.ctx()));
out.textures_delta.clear();
}
assert_eq!(app.session.tool_id(), "gradient");
assert_eq!(current(&app), paint, "the stop keeps its color");
assert_eq!(app.session.active().unwrap().selection.objects, selected, "the selection stays");
}
/// The gradient panel names its Angle and Aspect Ratio inputs.
#[test]
fn angle_and_aspect_fields_are_named() {
+14
View File
@@ -231,6 +231,14 @@ pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context) {
|| crate::dialogs::new_document_popup_open(d)
|| crate::dialogs::export_artboard_name_editing(app, d)
});
// Escape ends Brush Options' Key Color pick and leaves the dialog open: the Eyedropper
// switches back to the tool that armed it.
if !popup && pressed_anew(ctx, Key::Escape) && key_color_pick_armed(app) {
let view = app.view_info();
let r = app.session.tool_key(ToolKey::Escape, Mods::default(), view);
crate::canvas::apply_requests(app, r);
return;
}
// Escape in Preferences' search field with text clears the field first.
if !popup && pressed_anew(ctx, Key::Escape) && !crate::prefs_dialog::clear_search_on_escape(app, ctx) {
crate::dialogs::cancel(app);
@@ -387,6 +395,12 @@ pub(crate) fn pressed_anew(ctx: &egui::Context, key: Key) -> bool {
ctx.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::Key { key: k, pressed: true, repeat: false, .. } if *k == key)))
}
/// Is Brush Options open with its Key Color eyedropper armed, waiting for a click on the art?
fn key_color_pick_armed(app: &VectorcraftApp) -> bool {
let open = app.ui.dialog.as_ref().is_some_and(|d| d.kind == crate::dialogs::brush_options::KIND);
open && app.session.tool_id() == "eyedropper" && app.session.tool_options()["brushKeyColor"] == true
}
/// Takes this frame's repeats of `key` when the tool claims it: a press acts once, and they stay out
/// of the shortcuts. A chord a command is bound to keeps its repeats.
fn take_claimed_repeat(app: &mut VectorcraftApp, ctx: &egui::Context, key: Key, tool_key: ToolKey, view: ViewInfo) -> bool {
+1
View File
@@ -1741,6 +1741,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Hue Clockwise and Hue Counterclockwise, VectorCraft's own gradient methods, in the Gradient panel's Method menu and on `paint.editGradient` and `paint.setFill` (`method`: `hue-clockwise`, `hue-counterclockwise`): a linear, radial, conic or diamond gradient's colors mix around the hue wheel, with hue, saturation and brightness each changing evenly from one stop to the next and the hue angle keeping one direction, as the fixed-direction rules of [CSS Color 4](https://www.w3.org/TR/css-color-4/#hue-interpolation) do: falling with Hue Clockwise (red, magenta, blue), which is clockwise on the color wheels, and rising with Hue Counterclockwise (red, yellow, green). Hues less than half a color level apart count as one hue, so a color and its tint do not turn the wheel. A gray stop takes the hue of the stop it mixes with, and black its saturation too. The canvas and raster exports draw it through stops on that curve, within half a color level; Reverse Gradient turns the method the other way with the stops, so the ramp keeps its colors. SVG and PDF write it as an RGB image, EPS as a shading in process colors, and a legacy `.ai` file and the `.ai` editing data with the colors between its stops as stops of their own, with a warning.
- Gradient spread, VectorCraft's own setting: Pad, Repeat or Reflect, with a Repeats count of 1 to 100, in the Gradient panel and on `paint.editGradient` and `paint.setFill`; Repeat and Reflect run a linear, radial, conic or diamond gradient's stops that many times along the vector and on past its ends, the Gradient tool marks where the runs meet, and SVG writes and reads `spreadMethod`, CSS writes repeating gradients, PDF writes a conic's sweep shading over one run and the other kinds with their stops repeated across the shape, as EPS, legacy `.ai` and the `.ai` editing data do.
- The stop popover a double-click on a stop opens (the Gradient tool's annotator or the Gradient panel) has an eyedropper beside its Color and Swatches tabs: it closes the popover and samples the next colour clicked on the art into the stop, as the Gradient panel's eyedropper does (#4681).
Escape ends that eyedropper's pick, and Brush Options' Key Color pick, without sampling and returns to the tool that started it; the stop keeps its color, and Brush Options stays open with its Key Color until a new Escape cancels it (#8024, [Modify gradients, archived user guide](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=264)).
Cmd/Ctrl-click on the Gradient panel's Gradient Fill box or on the Tools panel's Gradient button resets the gradient of the active Fill or Stroke to the linear White, Black gradient, as one undo step ([Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html)).
With a gradient stop or a freeform gradient point selected, Alt-clicking a color swatch in the Swatches panel recolors it instead of the inactive Fill or Stroke.
- **Freeform gradient colors in their own model:** Object ▸ Expand and Object ▸ Create Gradient Mesh (`object.mesh.create`) mix a freeform gradient's points in the color model they share: points of C50 M20 Y0 K10 give mesh points of C50 M20 Y0 K10, and RGB points keep their values in a working RGB space other than sRGB. The canvas, the gradient chips and the SVG, PDF, EPS and EMF writers mix the points in that model too. PDF and EPS write a gradient whose points are all CMYK, or all Gray in a CMYK file, as a CMYK image, which PDF's Output settings convert as they convert any CMYK image. Points in different models mix in display RGB (on the canvas in a CMYK document that shows transparency, as the inks of each point), and a CMYK document stores the result of Expand as CMYK through the color settings. Points colored along CMYK stops (`paint.editGradient {stops}`, or a CMYK gradient switched to freeform) are CMYK, and so are a point `paint.freeform.splitLine` adds between CMYK points and a point `paint.freeform.addPoint` adds without `color` to CMYK points. Public reference: [Gradients](https://web.archive.org/web/20250714042311/https://helpx.adobe.com/illustrator/using/gradients.html) and [Meshes](https://web.archive.org/web/20250812201019/https://helpx.adobe.com/illustrator/using/meshes.html), which do not state how colors in different models mix; the rule is VectorCraft's own.