mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 23:44:45 +00:00
MCP: select.same.appearanceAttribute refuses an item that is not a whole number
An `item` given as text, a negative or fractional number, a boolean or a list was read as left out, so the command matched the Appearance panel's active item instead. It now fails with "`item` must be a whole number" and leaves the selection as it was; a left-out or null `item` still uses the active item.
This commit is contained in:
@@ -11,7 +11,7 @@ use super::object::can_align;
|
||||
use super::panelcmds::artboard_at;
|
||||
use super::wand::{fill_of, stroke_of};
|
||||
use super::{
|
||||
CommandSpec, Result, Session, bad, bool_or, checked_id, checked_ids_param, cmd, color_value, has_doc, has_selection, index, ok, str_param,
|
||||
CommandSpec, Result, Session, bad, bool_or, checked_id, checked_ids_param, cmd, color_value, has_doc, has_selection, index_opt, ok, str_param,
|
||||
switch_or, text_param,
|
||||
};
|
||||
use crate::DocState;
|
||||
@@ -222,7 +222,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Appearance Attribute",
|
||||
["Select", "Same"],
|
||||
None,
|
||||
"{item?: appearance item index} the objects sharing an appearance attribute of the first selected object: its fill or stroke `item` (default: the Appearance panel's active item), else its first effect, else its topmost fill (compound paths as select.same.fillColor)",
|
||||
"{item?: appearance item index (0-based whole number; default, or null: the Appearance panel's active item)} the objects sharing an appearance attribute of the first selected object: its fill or stroke `item` (default: the Appearance panel's active item), else its first effect, else its topmost fill (compound paths as select.same.fillColor)",
|
||||
has_selection,
|
||||
same_attribute
|
||||
),
|
||||
@@ -1103,10 +1103,10 @@ enum Attribute {
|
||||
|
||||
fn same_attribute(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "select.same.appearanceAttribute";
|
||||
let item = index_opt(p, "item", cmd)?.or(s.appearance_item());
|
||||
let st = s.doc()?;
|
||||
let (refn, _) = same_reference(st, cmd)?;
|
||||
let ap = &refn.appearance;
|
||||
let item = p.get("item").and_then(Value::as_u64).map(index).or(s.appearance_item());
|
||||
let attr = match (item.and_then(|i| ap.items.get(i)), ap.effects.first()) {
|
||||
(Some(it), _) => Attribute::Item(it.clone()),
|
||||
(None, Some(e)) => Attribute::Effect(e.clone()),
|
||||
|
||||
@@ -325,6 +325,26 @@ fn select_same_appearance_attribute() {
|
||||
run(&mut s, "select.set", json!({"ids": [a.0]}));
|
||||
run(&mut s, "select.same.appearanceAttribute", json!({"item": (1u64 << 32) + 1}));
|
||||
assert_eq!(s.doc().unwrap().selection.objects, vec![a, b]);
|
||||
// Null is the default: the shared effect.
|
||||
run(&mut s, "select.set", json!({"ids": [a.0]}));
|
||||
run(&mut s, "select.same.appearanceAttribute", json!({"item": null}));
|
||||
assert_eq!(s.doc().unwrap().selection.objects, vec![a, b]);
|
||||
}
|
||||
|
||||
/// Select > Same > Appearance Attribute refuses an `item` that is not a whole number and leaves
|
||||
/// the selection as it was.
|
||||
#[test]
|
||||
fn select_same_appearance_attribute_refuses_an_item_that_is_not_a_whole_number() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 10.0);
|
||||
run(&mut s, "effect.apply", json!({"effect": "distort.roughen"}));
|
||||
rect(&mut s, 100.0);
|
||||
run(&mut s, "select.set", json!({"ids": [a.0]}));
|
||||
for item in [json!("1"), json!(-1), json!(1.5), json!(true), json!([1])] {
|
||||
let e = s.execute("select.same.appearanceAttribute", &json!({"item": item})).unwrap_err().to_string();
|
||||
assert_eq!(e, "invalid parameters for `select.same.appearanceAttribute`: `item` must be a whole number", "{item}");
|
||||
assert_eq!(s.doc().unwrap().selection.objects, vec![a], "{item}");
|
||||
}
|
||||
}
|
||||
|
||||
/// With a member path of a compound path selected first, Select > Same > Graphic Style and
|
||||
|
||||
+4
-1
@@ -2785,7 +2785,10 @@ group selected on its own, or, for `symbolInstance`, an object that is not a sym
|
||||
leaves the selection empty. A selected object that is hidden or locked, inside a hidden or locked group or layer, on a
|
||||
template layer, on a locked artboard while nothing is isolated, or outside the isolated group is passed over. New art,
|
||||
such as a symbol instance just placed, is not passed over for being on a locked artboard while it stays selected. When
|
||||
the selection holds no other object, they return the error "nothing selected".
|
||||
the selection holds no other object, they return the error "nothing selected". `appearanceAttribute {item?}` takes
|
||||
the fill or stroke at appearance item `item`, or the Appearance panel's active item when the call gives none or null; a
|
||||
value that is not a whole number of 0 or more fails with "`item` must be a whole number" and leaves the selection as it
|
||||
was.
|
||||
|
||||
`select.object.allOnSameLayers` selects the objects on the layers and sublayers of the selected objects that can be
|
||||
selected. A selected object that is hidden or locked, inside a hidden or locked group or layer, on a template layer, on
|
||||
|
||||
@@ -1158,7 +1158,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
`path.reshapeSegment`, `object.blend.spine.reshapeSegment`, `path.convertAnchor`, `path.curvatureEdit`, `path.insertAnchor`, `path.moveAnchors`, `path.reshape`, `path.close` and the Pencil, Curvature, Knife, Eraser, Path Eraser, Smooth, Join and Blob Brush commands refuse a number, point or handle given as text, such as "10", and leave the document unchanged; `path.convertAnchor` refuses an `x` without a `y`, or a `y` without an `x`.
|
||||
`path.setHandle`, `path.moveAnchor`, `text.setPathHandle` (`anchor`), `path.insertAnchor` (`segment`), `artboard.reorder`, `library.moveGroup`, `graphicStyle.move` (`to`), `path.appendAnchor`, `path.close`, `path.reverse` (`subpath`) and the ruler origin commands (`artboard`) refuse a value that is not a whole number of 0 or more, such as `"3"` or `2.5`, with `` `anchor` must be a whole number ``, naming the key, instead of reporting it as missing or reading it as the default subpath or artboard; a null `artboard` is artboard 0 (`tests::params::a_malformed_index_is_not_missing_or_its_default`).
|
||||
The artboard commands that take `index`, `indices` or a replayed `selectedArtboards`, the artboard Align and Distribute commands (`artboard`, `activeArtboard`), `edit.newDocumentFromState` (`index`) and Paste in Place, in Front and in Back (`artboard`, `artboards`) report a value that is not a whole number as such, naming the key, and keep `no such artboard`, `no history state N` and the paste range messages for a whole number that names nothing; a null artboard `index` is `missing index`, and an `indices` value that is not a list, an empty list and a malformed entry each have their own message (`tests::panelcmds::artboard_lists_name_the_fault_and_the_key`).
|
||||
`guide.add` and `select.allOnArtboard` (`artboard`), `select.font` (`scope.artboards`) and `addon.select.byArtboards` (`artboards`) refuse an artboard that is not a whole number of 0 or more, such as `"1"`, `-1`, `1.5` or `true`, naming the key, instead of reporting it as a missing artboard or reading it as artboard 0, and leave the document and selection unchanged; a whole number past the last artboard is still `no such artboard`, and a null or left-out `artboard` keeps its default (`tests::menucmds::guide_add_refuses_an_artboard_that_is_not_a_whole_number`).
|
||||
`guide.add` and `select.allOnArtboard` (`artboard`), `select.font` (`scope.artboards`) and `addon.select.byArtboards` (`artboards`) refuse an artboard that is not a whole number of 0 or more, such as `"1"`, `-1`, `1.5` or `true`, naming the key, instead of reporting it as a missing artboard or reading it as artboard 0, and leave the document and selection unchanged; a whole number past the last artboard is still `no such artboard`, and a null or left-out `artboard` keeps its default (`tests::menucmds::guide_add_refuses_an_artboard_that_is_not_a_whole_number`). `select.same.appearanceAttribute` refuses such an `item` the same way instead of using the Appearance panel's active item (`tests::styles::select_same_appearance_attribute_refuses_an_item_that_is_not_a_whole_number`).
|
||||
`path.close` and `path.setHandle` (`independent`), `path.moveAnchors` (`patterns`), the Pencil (`closed`, `keepSelected`, `fill`), Curvature (`closed` and a point's `corner`), `path.curvatureEdit` (`corner`), `path.reshapeSegment` (`perpendicular`) and the Blob Brush (`keepSelected`, `mergeOnlySelection`, `merge`) refuse a value other than true, false or null, such as "true", and leave the document unchanged.
|
||||
Direct Selection's marquee selects the frame anchors of area type that lie inside it, and a click on a frame anchor selects that one; Shift toggles them. The selected frame anchors show filled. A drag of one of them moves all of them, the arrow keys nudge them, and the type reflows at its size (`text.reshapeArea`, which takes `items` to move the anchors of several frames in one step), as [Create text](http://web.archive.org/web/20220127090642/https://helpx.adobe.com/illustrator/using/creating-text.html) and [Selecting objects](http://web.archive.org/web/20211230015528/https://helpx.adobe.com/illustrator/using/selecting-objects.html) describe. When the selection also holds other objects, path anchors or ruler guides, or when another change to the document or the selection follows the pick, the type is selected whole.
|
||||
A press on a selected object's centre point (Attributes panel › Show Center) selects the object whole, and a drag from it moves the object as one Move, held by that point (#4891; test `the_centre_point_selects_and_moves_the_object_whole`).
|
||||
|
||||
Reference in New Issue
Block a user