mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-02 02:48:02 -06:00
Artboards: a Cut or Copy with the Artboard tool replays on its artboards
edit.copy and edit.cut chose the artboard route by the tool chosen, which the journal does not record. A replay in a new session acted on the objects selected there, or stopped with "nothing selected" when there were none. With the Artboard tool chosen, both now record selectedArtboards and art in the journal entry. A given selectedArtboards runs the artboard route with any tool and needs only a document. A recorded action leaves both values out, so it follows the tool chosen when it plays. Cut and Copy of objects record nothing new.
This commit is contained in:
@@ -139,7 +139,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Cut",
|
||||
["Edit"],
|
||||
Some("Cmd+X"),
|
||||
"{} (selected ruler guides go too; the Artboard tool chosen: artboard.cut)",
|
||||
"{selectedArtboards?: [n…], art?: bool} (as edit.copy) (selected ruler guides go too; the Artboard tool chosen, or selectedArtboards given: artboard.cut)",
|
||||
has_selection_guides_or_artboard_tool,
|
||||
cut
|
||||
),
|
||||
@@ -148,7 +148,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Copy",
|
||||
["Edit"],
|
||||
Some("Cmd+C"),
|
||||
"{} the selection with what it uses, and the selected ruler guides (pasted on the layer new art goes to, moved as the objects are; alone, where they were); the Artboard tool chosen: artboard.copy → {copied, guides}",
|
||||
"{selectedArtboards?: [n…] (the artboards the Artboard tool had selected, which the journal records for a replay; it runs artboard.copy with any tool chosen), art?: bool (default: the Artboard tool's moveArt option; the journal records it beside selectedArtboards)} the selection with what it uses, and the selected ruler guides (pasted on the layer new art goes to, moved as the objects are; alone, where they were); the Artboard tool chosen: artboard.copy → {copied, guides}",
|
||||
has_selection_guides_or_artboard_tool,
|
||||
copy
|
||||
),
|
||||
@@ -701,10 +701,27 @@ fn copy_cut_targets(s: &Session) -> Result<(bool, Vec<NodeId>)> {
|
||||
Ok((direct, roots))
|
||||
}
|
||||
|
||||
fn copy(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
/// Copy or Cut takes artboards: the Artboard tool is chosen, or the journal recorded the artboards
|
||||
/// it took then.
|
||||
fn takes_artboards(s: &Session, p: &Value) -> bool {
|
||||
s.tool_id() == "artboard" || p.get("selectedArtboards").is_some()
|
||||
}
|
||||
|
||||
/// Copy or Cut of artboards: `selectedArtboards` and `art` of `p`, or their defaults from the
|
||||
/// Artboard tool, which the journal entry records.
|
||||
fn copy_artboards(s: &mut Session, p: &Value, cut: bool) -> Result<Value> {
|
||||
let given: serde_json::Map<String, Value> =
|
||||
["selectedArtboards", "art"].into_iter().filter_map(|key| p.get(key).map(|v| (key.to_string(), v.clone()))).collect();
|
||||
let given = Value::Object(given);
|
||||
super::panelcmds::boards_and_art_noted(s, &given, if cut { "edit.cut" } else { "edit.copy" })?;
|
||||
super::panelcmds::artboard_copy(s, &given, cut)
|
||||
}
|
||||
|
||||
fn copy(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
switch_or(p, "art", false, "edit.copy")?;
|
||||
// The Artboard tool copies its artboard (and the art on it).
|
||||
if s.tool_id() == "artboard" {
|
||||
return super::panelcmds::artboard_copy(s, &json!({}), false);
|
||||
if takes_artboards(s, p) {
|
||||
return copy_artboards(s, p, false);
|
||||
}
|
||||
let (direct, targets) = copy_cut_targets(s)?;
|
||||
let st = s.doc()?;
|
||||
@@ -743,8 +760,9 @@ fn copy(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
}
|
||||
|
||||
fn cut(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if s.tool_id() == "artboard" {
|
||||
return super::panelcmds::artboard_copy(s, &json!({}), true);
|
||||
switch_or(p, "art", false, "edit.cut")?;
|
||||
if takes_artboards(s, p) {
|
||||
return copy_artboards(s, p, true);
|
||||
}
|
||||
// Ruler guides selected on their own: Copy takes them, Clear removes them.
|
||||
if s.doc()?.selection.is_empty() {
|
||||
|
||||
@@ -111,9 +111,8 @@ fn boards_and_art(s: &Session, p: &Value, cmd: &str) -> Result<(Vec<usize>, bool
|
||||
}
|
||||
|
||||
/// [`boards_and_art`], with both values added to the running command's journal entry, so a replay
|
||||
/// acts on the same artboards and art whatever the Artboard tool's state is then. `edit.cut` and
|
||||
/// `edit.copy` call [`artboard_copy`] without this and take no such params.
|
||||
fn boards_and_art_noted(s: &mut Session, p: &Value, cmd: &str) -> Result<(Vec<usize>, bool)> {
|
||||
/// acts on the same artboards and art whatever the Artboard tool's state is then.
|
||||
pub(crate) fn boards_and_art_noted(s: &mut Session, p: &Value, cmd: &str) -> Result<(Vec<usize>, bool)> {
|
||||
let (indices, art) = boards_and_art(s, p, cmd)?;
|
||||
note_artboards(s, p, &indices);
|
||||
s.note_journal("art", json!(art));
|
||||
|
||||
Reference in New Issue
Block a user