Paths: ⇧⌥⌘↩ intersects the path with the selection (#7726)

Main already has Add Path to Selection (⇧⌘↩) and Subtract Path from
Selection (⌥⌘↩) as engine commands (#8015). This adds the third,
path.intersectWithSelection (Cmd+Alt+Shift+Enter), next to them:
path.toSelection with mode "intersect", loading the path selected in
the Paths panel (or the one being drawn) from the UI as the other two do.

Tests: an engine test that the three fixed-mode commands match
path.toSelection with their mode whatever mode the params ask for, and
a UI test pressing ⇧⌘↩, ⌥⌘↩, ⇧⌥⌘↩ and ⌘↩ through the egui input, with
Photoshop 2025's areas for the same document (7200, 5200, 800, 2000 px).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Hector VillarrealandClaude Opus 5.5 committed 2026-11-05 19:13:59 -06:00
1 parent 9b02eac2c4
commit e4f2069b1b
7 files changed
+69 -4

No files matched your search

+1
View File
@@ -732,6 +732,7 @@ fn documents_filesystem_path_params(id: &str, params: &str) -> bool {
| "path.info"
| "path.addToSelection"
| "path.subtractFromSelection"
| "path.intersectWithSelection"
| "path.set"
| "path.transform"
| "path.moveAnchors"
+11
View File
@@ -230,6 +230,17 @@ pub fn specs() -> Vec<CommandSpec> {
run: |s, p| path_to_selection_with_mode(s, p, "subtract"),
journal: true,
},
// ⇧⌥⌘↩ / Ctrl+Alt+Shift+Enter intersects the path with the selection (#7726).
CommandSpec {
id: "path.intersectWithSelection",
label: "Intersect Path with Selection",
menu: &[],
shortcut: Some("Cmd+Alt+Shift+Enter"),
params: r##"{"name":str|"work"|"layer"="work","feather":px=0,"antiAlias":bool=true} (path.toSelection with mode "intersect")"##,
enabled: has_doc,
run: |s, p| path_to_selection_with_mode(s, p, "intersect"),
journal: true,
},
spec!("select.toWorkPath", "Make Work Path", [], r##"{"tolerance":0.5..10 px=2} → {subpaths,knots}"##, has_selection, select_to_work_path),
spec!(
"path.fill",
+2 -1
View File
@@ -371,7 +371,8 @@ pub(super) fn path_to_selection(s: &mut Session, p: &Value) -> Result<Value> {
Ok(json!({ "selected": selected }))
}
/// `path.toSelection` with the combine mode fixed by the command (⌘⇧↩ adds, ⌘⌥↩ subtracts);
/// `path.toSelection` with the combine mode fixed by the command (⌘⇧↩ adds, ⌘⌥↩ subtracts,
/// ⇧⌥⌘↩ intersects);
/// a `mode` in the params is overridden, the rest is forwarded and validated as usual.
pub(super) fn path_to_selection_with_mode(s: &mut Session, p: &Value, mode: &str) -> Result<Value> {
let mut q = match p {
@@ -460,6 +460,26 @@ fn open_pen_paths_make_the_same_selection_as_closed_paths() {
}
}
/// ⇧⌘↩, ⌥⌘↩ and ⇧⌥⌘↩'s commands are Make Selection from Path with their mode (#7726), whatever
/// `mode` the params ask for.
#[test]
fn the_fixed_mode_path_commands_combine_as_their_mode() {
let mut s = session(80, 80, 8);
let square = |x: f64| path_json(&vector::shapes::rect(x, 20.0, 30.0, 30.0));
s.execute("path.set", json!({"name": "Sq", "path": square(30.0)})).unwrap();
for (id, mode) in [("path.addToSelection", "add"), ("path.subtractFromSelection", "subtract"), ("path.intersectWithSelection", "intersect")] {
s.execute("select.rect", json!({"x": 10, "y": 20, "width": 30, "height": 30, "antiAlias": false})).unwrap();
s.execute("path.toSelection", json!({"name": "Sq", "mode": mode, "antiAlias": false})).unwrap();
let want = selection_mask(&s);
s.execute("select.rect", json!({"x": 10, "y": 20, "width": 30, "height": 30, "antiAlias": false})).unwrap();
s.execute(id, json!({"name": "Sq", "mode": "replace", "antiAlias": false})).unwrap();
assert_eq!(selection_mask(&s), want, "{id} is mode {mode}");
}
// Intersecting keeps only the 10 px both squares cover.
let mask = selection_mask(&s);
assert_eq!(mask.iter().filter(|v| **v > 0.5).count(), 10 * 30);
}
#[test]
fn selection_to_work_path_roundtrip_iou() {
let mut s = session(240, 180, 8);
+1
View File
@@ -264,6 +264,7 @@ impl PhotocraftApp {
| "path.toSelection"
| "path.addToSelection"
| "path.subtractFromSelection"
| "path.intersectWithSelection"
)
&& self.session.active().is_some_and(|st| st.doc.selection.is_some())
{
+9 -3
View File
@@ -207,10 +207,16 @@ fn invoke_file_commands(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str,
// ⌘↩ / Ctrl+Enter (#306): load the path selected in the Paths panel (or the one being
// drawn) as a selection.
"path.toSelection" if params.get("name").is_none() => crate::vector_ui::path_to_selection(app, params.clone()),
// ⌘⇧↩ / ⌘⌥↩ load the same path, adding it to or subtracting it from the selection.
"path.addToSelection" | "path.subtractFromSelection" if params.get("name").is_none() => {
// ⌘⇧↩ / ⌘⌥↩ / ⇧⌥⌘↩ load the same path, adding it to, subtracting it from or intersecting
// it with the selection.
"path.addToSelection" | "path.subtractFromSelection" | "path.intersectWithSelection" if params.get("name").is_none() => {
let mut p = params.as_object().cloned().unwrap_or_default();
p.insert("mode".into(), json!(if id == "path.addToSelection" { "add" } else { "subtract" }));
let mode = match id {
"path.addToSelection" => "add",
"path.subtractFromSelection" => "subtract",
_ => "intersect",
};
p.insert("mode".into(), json!(mode));
crate::vector_ui::path_to_selection(app, Value::Object(p))
}
// Layer › Rename Layer from a menu starts in-place renaming in the Layers panel.
@@ -537,3 +537,28 @@ fn cmd_shift_and_alt_enter_use_the_path_selected_in_the_paths_panel() {
press(&mut h, Key::Enter, Modifiers { alt: true, ..command() });
assert_eq!(selection(&h), Some([40, 40, 20, 20]), "{}", h.state().ui.status);
}
/// The selected area in pixels (partly selected pixels count in part).
fn selected_area(h: &Harness<'_, PhotocraftApp>) -> f32 {
let d = &h.state().session.active().unwrap().doc;
d.selection.as_ref().map_or(0.0, |s| s.read_region(d.bounds()).iter().sum())
}
/// #7726: as in Photoshop, ⇧⌘↩ adds the path to the selection, ⌥⌘↩ subtracts it and ⇧⌥⌘↩
/// intersects them. A 100×60 selection and a 100×20 path overlapping it by 40×20; the areas are
/// Photoshop 2025's for the same document.
#[test]
fn shift_and_option_with_cmd_enter_combine_the_path_with_the_selection() {
let alt = Modifiers { alt: true, ..command() };
let shift = Modifiers { shift: true, ..command() };
let both = Modifiers { shift: true, ..alt };
for (mods, area) in [(shift, 7200.0), (alt, 5200.0), (both, 800.0), (command(), 2000.0)] {
let mut h = harness();
h.state_mut().run("path.set", json!({"name": "work", "path": rect_path(80.0, 40.0, 100.0, 20.0)})).unwrap();
h.state_mut().run("select.rect", json!({"x": 20, "y": 20, "width": 100, "height": 60, "antiAlias": false})).unwrap();
h.state_mut().ui.tool = Tool::Brush;
h.run_steps(2);
press(&mut h, Key::Enter, mods);
assert!((selected_area(&h) - area).abs() < 0.5, "{mods:?}: {} px, wanted {area}: {}", selected_area(&h), h.state().ui.status);
}
}