From fc105400e360b2d71fb901fac2d7e4937307ea78 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Tue, 8 Jul 2025 00:31:45 +0200 Subject: [PATCH] fix(editor): group/ungroup-ing not creating history states --- editor/mainwindow.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/editor/mainwindow.cpp b/editor/mainwindow.cpp index 111c496..d571929 100644 --- a/editor/mainwindow.cpp +++ b/editor/mainwindow.cpp @@ -391,14 +391,16 @@ void MainWindow::connectActionHandlers() { auto model = Model::New(); std::shared_ptr firstParent; + bool done = false; std::shared_ptr selection = gDataModel->GetService(); for (auto object : selection->Get()) { if (firstParent == nullptr && object->GetParent().has_value()) firstParent = object->GetParent().value(); historyState.push_back(UndoStateInstanceReparented { object, object->GetParent().value(), model }); object->SetParent(model); + done = true; } - if (model->GetChildren().size() == 0) + if (!done) return; // Technically not how it works in the actual studio, but it's not an API-breaking change @@ -408,6 +410,7 @@ void MainWindow::connectActionHandlers() { model->SetParent(firstParent); historyState.push_back(UndoStateSelectionChanged { selection->Get(), { model } }); + undoManager.PushState(historyState); selection->Set({ model }); playSound("./assets/excluded/electronicpingshort.wav"); }); @@ -416,10 +419,12 @@ void MainWindow::connectActionHandlers() { UndoState historyState; std::vector> newSelection; + bool done = false; std::shared_ptr selection = gDataModel->GetService(); for (auto model : selection->Get()) { // Not a model, skip if (!model->IsA()) { newSelection.push_back(model); continue; } + done = true; for (auto object : model->GetChildren()) { historyState.push_back(UndoStateInstanceReparented { object, object->GetParent().value(), model->GetParent().value() }); @@ -431,7 +436,11 @@ void MainWindow::connectActionHandlers() { model->SetParent(std::nullopt); } + if (!done) + return; + historyState.push_back(UndoStateSelectionChanged { selection->Get(), newSelection }); + undoManager.PushState(historyState); selection->Set(newSelection); playSound("./assets/excluded/electronicpingshort.wav"); });