diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 203d924eec..da4cc4f360 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -6083,7 +6083,14 @@ int Tree::get_columns() const { void Tree::_scroll_moved(float) { _determine_hovered_item(); queue_redraw(); - popup_editor->hide(); + + if (scroll_pending > 0) { + // If both vertical and horizontal scroll happen in the same frame, + // this condition needs to cancel 2 movements, hence the counter. + scroll_pending--; + } else { + popup_editor->hide(); + } } Rect2 Tree::get_custom_popup_rect() const { @@ -6152,6 +6159,7 @@ void Tree::ensure_cursor_is_visible() { v_scroll->set_value(y_offset); } else if (y_offset + cell_h > v_scroll->get_value() + screen_h) { delta_v = y_offset - screen_h + cell_h - v_scroll->get_value(); + scroll_pending++; callable_mp((Range *)v_scroll, &Range::set_value).call_deferred(y_offset - screen_h + cell_h); } else if (y_offset < v_scroll->get_value()) { delta_v = y_offset - v_scroll->get_value(); @@ -6171,9 +6179,11 @@ void Tree::ensure_cursor_is_visible() { if (cell_w > screen_w) { delta_h = x_offset - h_scroll->get_value(); + scroll_pending++; h_scroll->set_value(x_offset); } else if (x_offset + cell_w > h_scroll->get_value() + screen_w) { delta_h = x_offset - screen_w + cell_w - h_scroll->get_value(); + scroll_pending++; callable_mp((Range *)h_scroll, &Range::set_value).call_deferred(x_offset - screen_w + cell_w); } else if (x_offset < h_scroll->get_value()) { delta_h = x_offset - h_scroll->get_value(); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index b0e02d8d79..52dedf6401 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -556,6 +556,7 @@ private: bool show_column_titles = false; bool popup_edit_committed = true; + int scroll_pending = 0; RID accessibility_scroll_element; RID stylebox_ci; // Separate canvas item for drawing native styleboxes. RID custom_ci; // Separate canvas item for drawing custom content.