Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't create an UndoRedo action if Autoload order doesn't change after Drag & Drop #99898

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions editor/editor_autoload_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,15 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &
Dictionary drop_data = p_data;
PackedStringArray autoloads = drop_data["autoloads"];

// Store the initial order of the autoloads for comparison.
Vector<int> initial_orders;
initial_orders.resize(autoload_cache.size());
int idx = 0;
for (const AutoloadInfo &F : autoload_cache) {
initial_orders.write[idx++] = F.order;
}

// Perform the drag-and-drop operation.
Vector<int> orders;
orders.resize(autoload_cache.size());

Expand All @@ -734,10 +743,14 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &
}
}

int i = 0;

idx = 0;
for (const AutoloadInfo &F : autoload_cache) {
orders.write[i++] = F.order;
orders.write[idx++] = F.order;
}

// If the order didn't change, we shouldn't create undo/redo actions.
if (orders == initial_orders) {
return;
}

orders.sort();
Expand All @@ -746,10 +759,9 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &

undo_redo->create_action(TTR("Rearrange Autoloads"));

i = 0;

idx = 0;
for (const AutoloadInfo &F : autoload_cache) {
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", "autoload/" + F.name, orders[i++]);
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", "autoload/" + F.name, orders[idx++]);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", "autoload/" + F.name, F.order);
}

Expand Down