From 94d0bbf2065298a02ed793976fd9536729907efa Mon Sep 17 00:00:00 2001 From: shweet Date: Tue, 6 Oct 2026 00:51:48 -0400 Subject: [PATCH] Split works on every selected frame Split (menu and shortcut) splits each selected frame that spans the time under the cursor or playhead; triggers are skipped. Co-Authored-By: Claude Opus 5.5 --- src/edit/edit.hpp | 1 + src/edit/frames.cpp | 9 +++++++++ src/imgui/window/timeline/edit.cpp | 6 +++--- src/imgui/window/timeline/menus.cpp | 2 +- tests/operations.cpp | 19 +++++++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/edit/edit.hpp b/src/edit/edit.hpp index 5a9f6eb..e14cc34 100644 --- a/src/edit/edit.hpp +++ b/src/edit/edit.hpp @@ -97,6 +97,7 @@ namespace anm2ed::edit Uids frames_reverse(model::Model&, const std::set&); Uids frames_bake(model::Model&, const std::set&, int, bool, bool); Uids frame_split(model::Model&, Reference, int); + Uids frames_split(model::Model&, const std::set&, int); Uids frames_move(model::Model&, const std::set&, Reference, int); Uids frame_durations_set(model::Model&, const std::map&); Uids trigger_at_frame_set(model::Model&, Reference, int); diff --git a/src/edit/frames.cpp b/src/edit/frames.cpp index fd379c6..80c6e40 100644 --- a/src/edit/frames.cpp +++ b/src/edit/frames.cpp @@ -165,6 +165,15 @@ namespace anm2ed::edit return {uid}; } + // Splits each of the frames that spans the time (last first, so earlier references stay valid). + Uids frames_split(Model& model, const std::set& references, int time) + { + Uids uids{}; + for (auto it = references.rbegin(); it != references.rend(); ++it) + std::ranges::copy(frame_split(model, *it, time), std::back_inserter(uids)); + return uids; + } + // Moves frames (from any tracks) into one track before the frame at the given index. Uids frames_move(Model& model, const std::set& frames, Reference target, int insertIndex) { diff --git a/src/imgui/window/timeline/edit.cpp b/src/imgui/window/timeline/edit.cpp index eb35f64..4259806 100644 --- a/src/imgui/window/timeline/edit.cpp +++ b/src/imgui/window/timeline/edit.cpp @@ -115,10 +115,10 @@ namespace anm2ed::imgui void TimelineContext::frame_split() { auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE); - if (selectedFrames.size() != 1) return; - auto targetReference = *selectedFrames.begin(); + std::erase_if(selectedFrames, is_trigger_reference); + if (selectedFrames.empty()) return; auto time = frameSplitTimeAtCursor.value_or((int)std::floor(playback.time)); - edit_push(EDIT_SPLIT_FRAME, [=](model::Model& model) { return edit::frame_split(model, targetReference, time); }); + edit_push(EDIT_SPLIT_FRAME, [=](model::Model& model) { return edit::frames_split(model, selectedFrames, time); }); } void TimelineContext::item_remove() diff --git a/src/imgui/window/timeline/menus.cpp b/src/imgui/window/timeline/menus.cpp index 65db714..e49f84e 100644 --- a/src/imgui/window/timeline/menus.cpp +++ b/src/imgui/window/timeline/menus.cpp @@ -122,7 +122,7 @@ namespace anm2ed::imgui actions.add(ACTION_DUPLICATE, [=, this]() { return !selectedBakeFrames.empty(); }, [&]() { frames_duplicate(); }); actions.add({.label = LABEL_SPLIT, .shortcut = SHORTCUT_SPLIT, - .isEnabled = [=, this]() { return selectedBakeFrames.size() == 1; }, + .isEnabled = [=, this]() { return !selectedBakeFrames.empty(); }, .run = [&]() { frame_split(); }}); actions.add(ACTION_REVERSE, [=, this]() { return isReverseFrames; }, [&]() { frames_reverse(); }); actions.separator(); diff --git a/tests/operations.cpp b/tests/operations.cpp index 63548c4..cc98497 100644 --- a/tests/operations.cpp +++ b/tests/operations.cpp @@ -348,3 +348,22 @@ TEST_CASE("frames_property_set copies one property to the frames that have it") CHECK(edit::is_frame_property_valid(edit::FrameProperty::SOUNDS, ItemType::TRIGGER)); CHECK_FALSE(edit::is_frame_property_valid(edit::FrameProperty::POSITION, ItemType::TRIGGER)); } + +TEST_CASE("frames_split splits every selected frame that spans the time") +{ + auto model = fixture_load("02_items.anm2"); + auto layerTrack = model.track_get({0, LAYER, 0}); + auto nullTrack = model.track_get({0, NULL_, 0}); + REQUIRE(layerTrack); + REQUIRE(nullTrack); + auto layerCount = layerTrack->frames.size(); + auto nullCount = nullTrack->frames.size(); + REQUIRE(layerTrack->frames[0].duration > 1); + REQUIRE(nullTrack->frames[0].duration > 1); + + auto uids = edit::frames_split(model, {{0, LAYER, 0, 0}, {0, NULL_, 0, 0}}, 0); + CHECK(uids.size() == 2); + CHECK(model.track_get({0, LAYER, 0})->frames.size() == layerCount + 1); + CHECK(model.track_get({0, NULL_, 0})->frames.size() == nullCount + 1); + CHECK(model.track_get({0, LAYER, 0})->frames[0].duration == 1); +}