mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 11:23:43 +01:00
Merge pull request #8880 from dotCooCoo/fix/align-to-selection-anchors-docs
Align: align.toSelection returns "artboard" only for one object with no anchor points selected
This commit is contained in:
4 files changed
+32
-3
No files matched your search
@@ -395,7 +395,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"align.toSelection",
|
||||
"Align to Selection",
|
||||
"",
|
||||
"{} the Align panel's Align to Selection button: Align To becomes Selection (saved with the preferences, ui.inspect › ui.align_to) and the key object, key guide or key anchor is let go → {alignTo: the choice the Align panel then shows: \"selection\", or \"artboard\" while one object is selected, since one object aligns to the artboard}; with the Artboard tool chosen the selected objects keep their key",
|
||||
"{} the Align panel's Align to Selection button: Align To becomes Selection (saved with the preferences, ui.inspect › ui.align_to) and the key object, key guide or key anchor is let go → {alignTo: the choice the Align panel then shows: \"selection\", or \"artboard\" while one object is selected with no anchor points selected and the Artboard tool is not chosen, since one object aligns to the artboard; \"selection\" while anchor points are selected (Direct Selection) and with the Artboard tool chosen}; with the Artboard tool chosen the selected objects keep their key",
|
||||
),
|
||||
(
|
||||
"align.toKeyObject",
|
||||
|
||||
@@ -396,7 +396,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"align.toSelection",
|
||||
"Align to Selection",
|
||||
"",
|
||||
"{} the Align panel's Align to Selection button: Align To becomes Selection (saved with the preferences, ui.inspect › ui.align_to) and the key object, key guide or key anchor is let go → {alignTo: the choice the Align panel then shows: \"selection\", or \"artboard\" while one object is selected, since one object aligns to the artboard}; with the Artboard tool chosen the selected objects keep their key",
|
||||
"{} the Align panel's Align to Selection button: Align To becomes Selection (saved with the preferences, ui.inspect › ui.align_to) and the key object, key guide or key anchor is let go → {alignTo: the choice the Align panel then shows: \"selection\", or \"artboard\" while one object is selected with no anchor points selected and the Artboard tool is not chosen, since one object aligns to the artboard; \"selection\" while anchor points are selected (Direct Selection) and with the Artboard tool chosen}; with the Artboard tool chosen the selected objects keep their key",
|
||||
),
|
||||
(
|
||||
"align.toKeyObject",
|
||||
|
||||
@@ -471,6 +471,20 @@ fn object_align_lists_the_align_to_choices() {
|
||||
assert_eq!(app.ui.align_to, AlignTo::Selection);
|
||||
}
|
||||
|
||||
/// With anchor points of one path selected (Direct Selection), Align to Selection returns
|
||||
/// `"selection"`: the points align to each other, so the lone path does not make it Artboard.
|
||||
#[test]
|
||||
fn align_to_selection_with_anchor_points_returns_selection() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
let id = app.run("path.create", json!({"d": "M100 40 L200 60 L150 160 Z"})).unwrap()["id"].as_u64().unwrap();
|
||||
app.ui.align_to = AlignTo::Artboard;
|
||||
app.run("select.anchors", json!({"id": id, "anchors": [[0, 0], [0, 1]], "mode": "set"})).unwrap();
|
||||
assert_eq!(app.run("align.toSelection", json!({})).unwrap(), json!({"alignTo": "selection"}));
|
||||
assert_eq!(app.ui.align_to, AlignTo::Selection);
|
||||
assert_eq!(align_to_checks(&app), [Some(true), Some(false), Some(false)]);
|
||||
}
|
||||
|
||||
/// With the Artboard tool chosen, Align to Key Object is off and fails, and Align to Artboard and
|
||||
/// Align to Selection store the choice while the selected objects keep their key.
|
||||
#[test]
|
||||
@@ -491,6 +505,19 @@ fn align_to_commands_with_the_artboard_tool() {
|
||||
assert_eq!(app.session.active().unwrap().selection.key.map(|k| k.0), front.as_u64(), "the key stays");
|
||||
}
|
||||
|
||||
/// With the Artboard tool chosen and one object selected with no anchor points, Align to Selection
|
||||
/// returns `"selection"`, the stored choice, not `"artboard"`.
|
||||
#[test]
|
||||
fn align_to_selection_with_one_object_and_the_artboard_tool_returns_selection() {
|
||||
let (mut app, back, _) = back_and_front();
|
||||
app.run("select.set", json!({"ids": [back]})).unwrap();
|
||||
app.ui.align_to = AlignTo::Artboard;
|
||||
app.select_tool("artboard");
|
||||
assert_eq!(app.run("align.toSelection", json!({})).unwrap(), json!({"alignTo": "selection"}));
|
||||
assert_eq!(app.ui.align_to, AlignTo::Selection);
|
||||
assert_eq!(align_to_checks(&app), [Some(true), Some(false), Some(false)]);
|
||||
}
|
||||
|
||||
/// Align to Key Object is off and fails when the topmost selected object can't be the key: a group
|
||||
/// selected with an object inside it.
|
||||
#[test]
|
||||
|
||||
+3
-1
@@ -7945,7 +7945,9 @@ and each item runs its command.
|
||||
|
||||
The Align panel's Align To choices are UI commands too, with no params: `align.toSelection`, `align.toKeyObject` and
|
||||
`align.toArtboard`. Each chooses what a click on its Align To button chooses and returns `{alignTo}`, the choice the
|
||||
panel then shows (`align.toSelection` returns `"artboard"` while one object is selected, which aligns to the artboard).
|
||||
panel then shows (`align.toSelection` returns `"artboard"` while one object is selected with no anchor points selected
|
||||
and the Artboard tool is not chosen, which aligns to the artboard; it returns `"selection"` while anchor points are
|
||||
selected with Direct Selection, which align to each other, and with the Artboard tool chosen).
|
||||
`align.toSelection` and `align.toArtboard` store the choice (`ui.inspect` › `ui.align_to`) and let the key go; with the
|
||||
Artboard tool chosen they store it and the selected objects keep their key. With no key, `align.toKeyObject` makes the
|
||||
topmost of two or more selected objects the key object, or a ruler guide selected with one object the key guide, and
|
||||
|
||||
Reference in new issue
Block a user