mirror of
https://github.com/storytold/AniCraft.git
synced 2026-11-28 17:19:31 +01:00
Merge outside PR #545: Keep the frame clipboard when Cut Frames fails
This commit is contained in:
commit
c223b3894a
2 files changed
+24
-5
No files matched your search
@@ -77,7 +77,7 @@ fn slice(layer: &Layer, frame: u32, count: u32) -> Result<Vec<Arc<Keyframe>>> {
|
||||
.collect())
|
||||
}
|
||||
|
||||
fn copy_frames(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
fn collect_frames(s: &Session, p: &Value) -> Result<FrameClipboard> {
|
||||
let (_, frame) = target(s, p)?;
|
||||
let count = count_param(p)?;
|
||||
let mut ids = target_layers(s, p)?;
|
||||
@@ -94,16 +94,20 @@ fn copy_frames(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
return Err(EngineError::State("no frames there to copy".into()));
|
||||
}
|
||||
let elements: Vec<Element> = clip.layers.iter().flat_map(|l| l.keys.iter().flat_map(|k| k.elements.iter().map(|e| (**e).clone()))).collect();
|
||||
let n = clip.layers.len();
|
||||
let sounds: Vec<anicraft_doc::SoundId> = clip.layers.iter().flat_map(|l| l.keys.iter().filter_map(|k| k.sound.as_ref().map(|f| f.sound))).collect();
|
||||
let carried = crate::transfer::carry(s, &elements, sounds);
|
||||
s.frame_clipboard = FrameClipboard { carried, ..clip };
|
||||
Ok(json!({"copied": count, "layers": n}))
|
||||
Ok(FrameClipboard { carried, ..clip })
|
||||
}
|
||||
|
||||
fn copy_frames(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
s.frame_clipboard = collect_frames(s, p)?;
|
||||
Ok(json!({"copied": s.frame_clipboard.count, "layers": s.frame_clipboard.layers.len()}))
|
||||
}
|
||||
|
||||
fn cut_frames(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
copy_frames(s, p)?;
|
||||
let clip = collect_frames(s, p)?;
|
||||
remove_frame(s, p)?;
|
||||
s.frame_clipboard = clip;
|
||||
Ok(json!({"cut": s.frame_clipboard.count, "layers": s.frame_clipboard.layers.len()}))
|
||||
}
|
||||
|
||||
|
||||
@@ -1458,6 +1458,21 @@ fn copy_and_paste_frames_inserts_and_cuts_at_the_selection_edges() {
|
||||
assert!(s.execute("timeline.copy_frames", &json!({"frame": 500})).is_err(), "nothing there");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_cut_keeps_previously_copied_frames() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "draw.rect", json!({"x": 0, "y": 0, "w": 10, "h": 10}));
|
||||
run(&mut s, "timeline.copy_frames", json!({"frame": 0}));
|
||||
run(&mut s, "layer.new", json!({}));
|
||||
|
||||
let err = s.execute("timeline.cut_frames", &json!({"frame": 0})).unwrap_err();
|
||||
assert!(matches!(err, EngineError::State(message) if message == "cannot remove the layer's only frame"));
|
||||
|
||||
run(&mut s, "timeline.paste_frames", json!({"frame": 0}));
|
||||
let pasted = s.active_layer().unwrap().keyframe_at(0).unwrap();
|
||||
assert_eq!(pasted.elements.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pasting_several_layers_fills_the_layers_below_and_creates_missing_ones() {
|
||||
let mut s = Session::new(anicraft_doc::sample::demo());
|
||||
|
||||
Reference in new issue
Block a user