fix(ui): restore layer pixels after leaving Quick Mask (#17564)

This commit is contained in:
makesomethingshit committed 2026-11-29 12:19:55 +09:00
1 parent 7199576a93
commit d16a8f8dfa
3 files changed
+114

No files matched your search

+13
View File
@@ -173,6 +173,19 @@ impl PhotocraftApp {
self.ui.vector_mask_target = true;
self.ui.mask_target = false;
}
// Quick Mask takes over from the pixel layer's mask. Drop the previous thumbnail
// target as its swatches are put away, so it can't take over again on exit.
None if self.ui.mask_target
&& self.session.tools.mask_targeted
&& channel == ChannelTarget::Composite
&& st.doc.quick_mask.is_some()
&& st
.active_layer
.and_then(|id| st.doc.layer(id))
.is_some_and(|layer| matches!(layer.content, photocraft_doc::LayerContent::Raster(_))) =>
{
self.ui.mask_target = false;
}
None => {}
}
if self.ui.mask_target || self.ui.vector_mask_target {
+2
View File
@@ -874,6 +874,8 @@ mod live_retouch_tests;
mod lock_layers_shortcut_tests;
#[cfg(test)]
mod pencil_tests;
#[cfg(all(test, not(target_arch = "wasm32")))]
mod quick_mask_exit_target_tests;
#[cfg(test)]
mod smart_objects_menu_tests;
#[cfg(test)]
@@ -0,0 +1,99 @@
//! Quick Mask exit returns the Pencil and panels to layer pixels (#17564).
use craft::layers::ui::tree::{LayerPart, LayerTree};
use egui::Modifiers;
use serde_json::json;
use crate::PhotocraftApp;
use crate::canvas::{ToolEvent, tool_event};
use crate::control::{ControlRequest, Reply};
use crate::panels::{channels_panel, layers_tree::PhotoLayers, toolbar};
use crate::state::Tool;
fn app() -> Box<PhotocraftApp> {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 64, "height": 48, "background": "transparent"})).unwrap();
app.ui.tool = Tool::Pencil;
crate::paint_mouse::sync_tool_brush(&mut app);
app.run("tools.setBrush", json!({"brush": {"size": 3}})).unwrap();
app.run("tools.setColors", json!({"foreground": "#0000ff", "background": "#ffff00"})).unwrap();
app
}
fn swatches(app: &PhotocraftApp) -> [[f32; 4]; 2] {
[app.session.tools.foreground, app.session.tools.background]
}
fn pencil_click(app: &mut PhotocraftApp) {
tool_event(app, ToolEvent::Down { x: 20.5, y: 20.5, pressure: 1.0 }, Modifiers::NONE);
tool_event(app, ToolEvent::Up { x: 20.5, y: 20.5 }, Modifiers::NONE);
}
fn active_layer(app: &PhotocraftApp) -> &photocraft_doc::Layer {
let st = app.session.active().unwrap();
st.doc.layer(st.active_layer.unwrap()).unwrap()
}
fn toggle(app: &mut PhotocraftApp, expected: bool, via_control: bool) {
if via_control {
let ctx = app.ctx().clone();
let (request, _reply) = ControlRequest::new("engine.execute", json!({"command": toolbar::QUICK_MASK}));
let reply = match crate::control::handle(app, &ctx, &request) {
Reply::Done(reply) => Some(reply),
_ => None,
};
let reply = reply.expect("Quick Mask must finish synchronously");
assert_eq!(reply["ok"], true, "{reply}");
assert_eq!(reply["result"]["quickMask"], expected);
} else {
assert_eq!(app.run(toolbar::QUICK_MASK, json!({})).unwrap()["quickMask"], expected);
}
}
#[test]
fn leaving_quick_mask_returns_pencil_panels_and_swatches_to_layer_pixels() {
for via_control in [false, true] {
let mut app = app();
let rgb = swatches(&app);
app.run("layer.layerMask.revealAll", json!({})).unwrap();
assert!(app.layer_mask_targeted());
app.run("tools.setColors", json!({"foreground": "#000000", "background": "#ffffff"})).unwrap();
assert_ne!(swatches(&app), rgb);
let before_pixel = active_layer(&app).surface().unwrap().rgba(20, 20);
let before_mask = active_layer(&app).mask.as_ref().unwrap().surface.sample_channel(20, 20, 0);
toggle(&mut app, true, via_control);
toggle(&mut app, false, via_control);
let exit_swatches = swatches(&app);
let exit_targets: Vec<_> = channels_panel::rows(&app).into_iter().filter(|row| row.targeted).map(|row| row.key).collect();
let st = app.session.active().unwrap();
let exit_layer_target = PhotoLayers::new(&app, st, &app.ui.layer_filter, false, None).selection().target;
pencil_click(&mut app);
let layer = active_layer(&app);
let mask = layer.mask.as_ref().unwrap();
let pixel = layer.surface().unwrap().rgba(20, 20);
assert_eq!(
(pixel, mask.surface.sample_channel(20, 20, 0)),
(rgb[0], before_mask),
"Pencil must paint the layer rather than its mask (control: {via_control}, pre-stroke pixel: {before_pixel:?})"
);
assert_eq!(exit_layer_target, LayerPart::Pixels, "Layers targets the pixel thumbnail");
assert!(exit_targets.contains(&channels_panel::Row::Composite));
assert!(!exit_targets.contains(&channels_panel::Row::LayerMask));
assert_eq!(exit_swatches, rgb, "the toolbar uses the RGB swatches again");
}
}
#[test]
fn leaving_quick_mask_without_a_layer_mask_keeps_the_pixel_target() {
let mut app = app();
let rgb = swatches(&app);
toggle(&mut app, true, false);
toggle(&mut app, false, false);
assert_eq!(swatches(&app), rgb);
assert!(channels_panel::rows(&app).iter().any(|row| row.key == channels_panel::Row::Composite && row.targeted));
pencil_click(&mut app);
assert_eq!(active_layer(&app).surface().unwrap().rgba(20, 20), rgb[0]);
}