From 1f4044c0f1e666002e687342729f15e3190b7e8a Mon Sep 17 00:00:00 2001 From: kobewi Date: Thu, 17 Jul 2025 14:29:44 +0200 Subject: [PATCH] Fix inconsistent column in Tree click detection --- scene/gui/tree.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 3faaeae01e..da73fbfeb7 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -6037,13 +6037,22 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_ } for (int i = 0; i < columns.size(); i++) { - int w = get_column_width(i); - if (pos.x < w) { - r_column = i; + int col_width = get_column_width(i); + if (p_item->cells[i].expand_right) { + int plus = 1; + while (i + plus < columns.size() && !p_item->cells[i + plus].editable && p_item->cells[i + plus].mode == TreeItem::CELL_MODE_STRING && p_item->cells[i + plus].text.is_empty() && p_item->cells[i + plus].icon.is_null() && p_item->cells[i + plus].buttons.is_empty()) { + col_width += theme_cache.h_separation; + col_width += get_column_width(i + plus); + plus++; + } + } + + if (pos.x < col_width) { + r_column = i; return p_item; } - pos.x -= w; + pos.x -= col_width; } return nullptr;