Marquee guide selection: one shared helper for both selection tools

This commit is contained in:
bflatastic committed 2026-10-14 08:01:50 +07:00
1 parent 8796aa9d85
commit ed96b2ff65
3 files changed
+15 -34

No files matched your search

+2 -16
View File
@@ -730,22 +730,8 @@ impl Tool for DirectSelectionTool {
}
sel.retain(|(id, _)| cx.doc.is_editable(*id));
let items: Vec<Value> = sel.iter().map(|(id, v)| json!({"id": id.0, "anchors": anchors_json(v)})).collect();
let guides = crate::rulerguide::guides_in_rect(cx, r);
let mut out = vec![];
if toggle {
if !items.is_empty() {
out.push(Action::Exec("select.anchorsMany".into(), json!({"items": items, "mode": "toggle"})));
}
if !guides.is_empty() {
out.push(Action::Exec("guide.select".into(), json!({ "indexes": guides, "toggle": true })));
}
} else {
out.push(Action::Exec("select.anchorsMany".into(), json!({"items": items, "mode": "set"})));
if !guides.is_empty() {
out.push(Action::Exec("guide.select".into(), json!({ "indexes": guides, "toggle": true })));
}
}
out
let art = Action::Exec("select.anchorsMany".into(), json!({"items": items, "mode": if toggle { "toggle" } else { "set" }}));
std::iter::once(art).chain(crate::rulerguide::marquee_select(cx, r)).collect()
}
_ => vec![],
}
+11 -2
View File
@@ -2,7 +2,8 @@
//! made where it is released over the canvas: with the Artboard tool, an artboard guide of the
//! active artboard. For the selection tools ([`GuideEdit`]), a press on a guide selects it (Shift
//! adds it to the selected guides or, released without a drag, takes it out); dragging moves the
//! selected guides (Alt copies them). A dragged guide snaps ([`GuideSnap`]): with Shift to the
//! selected guides (Alt copies them), and a marquee selects the guides it crosses along with the
//! art ([`marquee_select`]). A dragged guide snaps ([`GuideSnap`]): with Shift to the
//! ruler's ticks, else to whole pixels, the grid, with Smart Guides the art's and the artboards'
//! edges, centres and anchors, or with Snap to Point the anchors. Dropped off the canvas onto its
//! ruler, a moved guide is deleted. Hidden or locked guides (View › Guides), and guides on a hidden
@@ -32,8 +33,16 @@ pub fn guide_at(cx: &ToolContext, p: Point) -> Option<usize> {
.map(|(i, _)| i)
}
/// What a selection tool's marquee `r` does to the ruler guides, after its action selecting the
/// art: the guides it crosses join the selection (with a Shift marquee, the selected ones leave
/// it, as with a Shift-click on a guide).
pub fn marquee_select(cx: &ToolContext, r: Rect) -> Option<Action> {
let guides = guides_in_rect(cx, r);
(!guides.is_empty()).then(|| Action::Exec("guide.select".into(), json!({ "indexes": guides, "toggle": true })))
}
/// The editable ruler guides intersecting marquee rectangle `r`.
pub fn guides_in_rect(cx: &ToolContext, r: Rect) -> Vec<usize> {
fn guides_in_rect(cx: &ToolContext, r: Rect) -> Vec<usize> {
if !cx.guides {
return vec![];
}
+2 -16
View File
@@ -459,22 +459,8 @@ impl Tool for SelectionTool {
return if toggle { vec![] } else { vec![Action::Exec("select.none".into(), json!({}))] };
}
let ids: Vec<NodeId> = marquee(cx.doc, r, cx.isolation, false);
let guides = crate::rulerguide::guides_in_rect(cx, r);
let mut out = vec![];
if toggle {
if !ids.is_empty() {
out.push(Action::Exec("select.toggle".into(), json!({ "ids": json_ids(&ids) })));
}
if !guides.is_empty() {
out.push(Action::Exec("guide.select".into(), json!({ "indexes": guides, "toggle": true })));
}
} else {
out.push(Action::Exec("select.set".into(), json!({ "ids": json_ids(&ids) })));
if !guides.is_empty() {
out.push(Action::Exec("guide.select".into(), json!({ "indexes": guides, "toggle": true })));
}
}
out
let art = Action::Exec(if toggle { "select.toggle" } else { "select.set" }.into(), json!({ "ids": json_ids(&ids) }));
std::iter::once(art).chain(crate::rulerguide::marquee_select(cx, r)).collect()
}
_ => vec![],
}