mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Scripts: Fit Artboard to artwork bounds does nothing on a locked or empty artboard
app.executeMenuCommand('Fit Artboard to artwork bounds') threw the
command's error when the active artboard was locked or had no art on
it. The canvas's right-click menu dims Fit to Artwork Bounds then
(DocState::any_art_to_fit), so the script now does nothing and adds
no undo step, as for the other menu items that are not available. The docs state
that an available menu item runs its command and that an error that
command returns throws.
The host-versus-checker name table lists
Application.prototype.executeMenuCommand.
This commit is contained in:
1 parent
34abb11d0e
commit
0ea397db72
4 files changed
+29
-5
No files matched your search
@@ -795,7 +795,10 @@ const MENU_COMMANDS: &[(&str, &str)] = &[
|
||||
/// <https://www.indesignjs.de/indesignapi/illustrator/illustrator.d.ts> describes the method. A
|
||||
/// name it does not list throws an error that names it. A menu item that is not available, with
|
||||
/// no document open or nothing selected that it acts on, does nothing, as a dimmed menu item does
|
||||
/// (VectorCraft's own rule). `Fit Artboard to artwork bounds` fits the active artboard.
|
||||
/// (VectorCraft's own rule). A menu item the menus show as available runs its command, and an error
|
||||
/// that command returns throws. `Fit Artboard to artwork bounds` fits the active artboard, and does
|
||||
/// nothing when that artboard is locked or has no art, as the canvas's right-click menu dims
|
||||
/// the item then ([`DocState::any_art_to_fit`]).
|
||||
fn app_menu_command(h: &Host, a: &[Data]) -> Answer {
|
||||
let Data::String(name) = arg(a, 1) else { return Err(HostError::Type("executeMenuCommand needs a menu command, as a string".into())) };
|
||||
if name.len() > MAX_TEXT_BYTES {
|
||||
@@ -811,7 +814,13 @@ fn app_menu_command(h: &Host, a: &[Data]) -> Answer {
|
||||
return Ok(Data::Undefined);
|
||||
}
|
||||
match (id, s.active()) {
|
||||
("artboard.fitToArt", Some(st)) => json!({"index": active_artboard(st)}),
|
||||
("artboard.fitToArt", Some(st)) => {
|
||||
let index = active_artboard(st);
|
||||
if !st.any_art_to_fit(&[index]) {
|
||||
return Ok(Data::Undefined);
|
||||
}
|
||||
json!({"index": index})
|
||||
}
|
||||
_ => json!({}),
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user