summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-05-22 19:28:13 +0200
committerGitHub <noreply@github.com>2022-05-22 19:28:13 +0200
commit2bb3c97a52b1729e6acf00e9c4d0233a79fd1585 (patch)
tree8b4227c0e91fe524d06e3b2792239f3e0108f436 /editor
parenta80793fcb855404261163d6b2b0b7cb2c957e46f (diff)
parent33b29704926f623f97402e0cfbf2591a163b8ab6 (diff)
Merge pull request #61282 from kleonc/inspector_array_reorder_crash_fix
`EditorPropertyArray` Fix crash when drag-reordering array elements in the inspector
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_properties_array_dict.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp
index 25016c7f82..608121d806 100644
--- a/editor/editor_properties_array_dict.cpp
+++ b/editor/editor_properties_array_dict.cpp
@@ -607,11 +607,16 @@ void EditorPropertyArray::_reorder_button_gui_input(const Ref<InputEvent> &p_eve
Variant array = object->get_array();
int size = array.call("size");
- if ((reorder_to_index == 0 && mm->get_relative().y < 0.0f) || (reorder_to_index == size - 1 && mm->get_relative().y > 0.0f)) {
+ // Cumulate the mouse delta, many small changes (dragging slowly) should result in reordering at some point.
+ reorder_mouse_y_delta += mm->get_relative().y;
+
+ // Reordering is done by moving the dragged element by +1/-1 index at a time based on the cumulated mouse delta so if
+ // already at the array bounds make sure to ignore the remaining out of bounds drag (by resetting the cumulated delta).
+ if ((reorder_to_index == 0 && reorder_mouse_y_delta < 0.0f) || (reorder_to_index == size - 1 && reorder_mouse_y_delta > 0.0f)) {
+ reorder_mouse_y_delta = 0.0f;
return;
}
- reorder_mouse_y_delta += mm->get_relative().y;
float required_y_distance = 20.0f * EDSCALE;
if (ABS(reorder_mouse_y_delta) > required_y_distance) {
int direction = reorder_mouse_y_delta > 0.0f ? 1 : -1;