Color Wheel: Copy Color As does not report a copy without a window

Without a window to copy through, a Copy Color As item still answers its
text, puts nothing on the clipboard and leaves the status bar as it was.
Before, the status bar said the color was copied.
This commit is contained in:
dotCooCoo committed 2026-11-24 23:48:52 -08:00
1 parent dd8ea1da13
commit adf9fb23f6
3 files changed
+18 -5

No files matched your search

+5 -4
View File
@@ -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<Value, String> {
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 }))
}
@@ -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]
+2 -1
View File
@@ -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