Fix UI focus being shown when it shouldn't

This commit is contained in:
Michael Alexsander
2025-10-07 12:05:34 -03:00
parent 06faefc9f4
commit e32b9274a3
7 changed files with 39 additions and 16 deletions

View File

@ -3285,9 +3285,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
click_handled = true;
popup_pressing_edited_item = p_item;
popup_pressing_edited_item_column = col;
pressing_item_rect = Rect2(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs) - theme_cache.offset, Size2(col_width, item_h));
pressing_for_editor_text = editor_text;
pressing_for_editor = true;
return -1; // Select.
@ -3361,14 +3358,15 @@ void Tree::_text_editor_gui_input(const Ref<InputEvent> &p_event) {
if (p_event->is_action_pressed("ui_text_newline_blank", true)) {
accept_event();
} else if (p_event->is_action_pressed("ui_text_newline")) {
bool hide_focus = !text_editor->has_focus(true);
popup_edit_committed = true; // End edit popup processing.
popup_editor->hide();
_apply_multiline_edit();
_apply_multiline_edit(hide_focus);
accept_event();
}
}
void Tree::_apply_multiline_edit() {
void Tree::_apply_multiline_edit(bool p_hide_focus) {
if (!popup_edited_item) {
return;
}
@ -3387,6 +3385,7 @@ void Tree::_apply_multiline_edit() {
}
}
grab_focus(p_hide_focus);
item_edited(popup_edited_item_col, popup_edited_item);
queue_redraw();
}
@ -3400,6 +3399,8 @@ void Tree::_line_editor_submit(String p_text) {
return; // ESC pressed, app focus lost, or forced close from code.
}
bool hide_focus = !line_editor->has_focus(true);
popup_edit_committed = true; // End edit popup processing.
popup_editor->hide();
@ -3432,6 +3433,7 @@ void Tree::_line_editor_submit(String p_text) {
}
}
grab_focus(hide_focus);
item_edited(popup_edited_item_col, popup_edited_item);
queue_redraw();
}
@ -4404,6 +4406,8 @@ bool Tree::edit_selected(bool p_force_edit) {
}
popup_rect.position += get_screen_position();
bool hide_focus = !has_focus(true);
line_editor->clear();
line_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::range_step_decimals(c.step)));
line_editor->select_all();
@ -4420,10 +4424,12 @@ bool Tree::edit_selected(bool p_force_edit) {
popup_editor->popup();
popup_editor->child_controls_changed();
line_editor->grab_focus();
line_editor->grab_focus(hide_focus);
return true;
} else if (c.mode == TreeItem::CELL_MODE_STRING && c.edit_multiline) {
bool hide_focus = !has_focus(true);
line_editor->hide();
text_editor->clear();
@ -4440,7 +4446,7 @@ bool Tree::edit_selected(bool p_force_edit) {
popup_editor->popup();
popup_editor->child_controls_changed();
text_editor->grab_focus();
text_editor->grab_focus(hide_focus);
return true;
}