diff --git a/crates/ui-egui/src/panels/color_wheel.rs b/crates/ui-egui/src/panels/color_wheel.rs index f2208c9dad..9661c45a48 100644 --- a/crates/ui-egui/src/panels/color_wheel.rs +++ b/crates/ui-egui/src/panels/color_wheel.rs @@ -523,7 +523,9 @@ pub(crate) fn menu_states(app: &VectorcraftApp, states: &mut CommandStates) { /// Copy Color As: put `color.format`'s text in `notation` of the color the panel shows on the /// clipboard, with the opacity of what the row of Show Opacity edits when it has one, and say in /// the status bar what was copied. Without a solid color nothing is copied and the answer is -/// null; an error of `color.format` goes to the status bar. → `{text}`. +/// null; an error of `color.format` goes to the status bar. Without a window to copy through, +/// nothing is copied and the status bar stays as it was, and the answer still holds the text. +/// → `{text}`. pub(crate) fn copy_color_as(app: &mut VectorcraftApp, notation: &str) -> Result { let tgt = target_now(app); let Some(color) = tgt.color() else { return Ok(Value::Null) }; @@ -535,9 +537,8 @@ pub(crate) fn copy_color_as(app: &mut VectorcraftApp, notation: &str) -> Result< match app.run("color.format", p) { Ok(r) => { let text = r["text"].as_str().unwrap_or_default().to_string(); - if let Some(ctx) = &app.ui_ctx { - ctx.copy_text(text.clone()); - } + let Some(ctx) = &app.ui_ctx else { return Ok(json!({ "text": text })) }; + ctx.copy_text(text.clone()); app.status(format!("Copied the color as {text}")); Ok(json!({ "text": text })) } diff --git a/crates/ui-egui/src/panels/tests_color_wheel_copy.rs b/crates/ui-egui/src/panels/tests_color_wheel_copy.rs index f041b62d59..1ffd93f70e 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel_copy.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel_copy.rs @@ -71,6 +71,17 @@ fn css_rgb_copies_the_color_and_the_opacity() { assert_eq!(undo_count(&app), before, "copying records no undo step"); } +/// Without a window to copy through, an item answers its text and the status bar does not say it +/// was copied. +#[test] +fn without_a_window_the_text_is_answered_and_not_reported_as_copied() { + let mut app = app(50.0); + app.ui_ctx = None; + app.ui.status.clear(); + assert_eq!(run(&mut app, "ui.colorWheel.copy.hex", &json!({})), Some(Ok(json!({"text": "#336699"})))); + assert_eq!(app.ui.status, ""); +} + /// Hex and CMYK Values never carry the opacity; Hex with Alpha always does, as `ff` at 100 %; CSS /// adds it only under 100 %. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 0dfbf4b224..fd322eff7e 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -769,7 +769,8 @@ rgb(), CSS hsl(), CSS oklch() or CMYK Values, the six `color.format` notations, edits when it has one (whether or not that row shows), and the status bar shows what was copied. Its items are the menu commands `ui.colorWheel.copy.hex`, `ui.colorWheel.copy.hexAlpha`, `ui.colorWheel.copy.rgb`, `ui.colorWheel.copy.hsl`, `ui.colorWheel.copy.oklch` and `ui.colorWheel.copy.cmyk`, which answer `{text}`, or null without a solid color. They are gray without a solid color, and CSS oklch() is also gray -while the working RGB space is not sRGB. +while the working RGB space is not sRGB. Without a window to copy through, an item puts nothing on the clipboard and +leaves the status bar as it was, and still answers `{text}`. In remote desktop mode, `invoke_menu` with `{"command":"ui.sampleScreenColor","params":{}}` shows the system's screen color sampler and returns `null` before a color is picked: the system's sampler on macOS, the XDG desktop