Skip to content

Commit 7d4d63b

Browse files
committed
Fix Tree and FileSystemList edit popup double events and ESC behavior.
1 parent f4b047a commit 7d4d63b

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

editor/filesystem_dock.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ Control *FileSystemList::make_custom_tooltip(const String &p_text) const {
7979
}
8080

8181
void FileSystemList::_line_editor_submit(const String &p_text) {
82+
if (popup_edit_commited) {
83+
return; // Already processed by _text_editor_popup_modal_close
84+
}
85+
86+
if (popup_editor->get_hide_reason() == Popup::HIDE_REASON_CANCELED) {
87+
return; // ESC pressed, app focus lost, or forced close from code.
88+
}
89+
90+
popup_edit_commited = true; // End edit popup processing.
8291
popup_editor->hide();
8392

8493
emit_signal(SNAME("item_edited"));
@@ -127,6 +136,7 @@ bool FileSystemList::edit_selected() {
127136
line_editor->set_text(name);
128137
line_editor->select(0, name.rfind("."));
129138

139+
popup_edit_commited = false; // Start edit popup processing.
130140
popup_editor->popup();
131141
popup_editor->child_controls_changed();
132142
line_editor->grab_focus();
@@ -138,8 +148,12 @@ String FileSystemList::get_edit_text() {
138148
}
139149

140150
void FileSystemList::_text_editor_popup_modal_close() {
151+
if (popup_edit_commited) {
152+
return; // Already processed by _text_editor_popup_modal_close
153+
}
154+
141155
if (popup_editor->get_hide_reason() == Popup::HIDE_REASON_CANCELED) {
142-
return;
156+
return; // ESC pressed, app focus lost, or forced close from code.
143157
}
144158

145159
_line_editor_submit(line_editor->get_text());

editor/filesystem_dock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class FileSystemTree : public Tree {
5959
class FileSystemList : public ItemList {
6060
GDCLASS(FileSystemList, ItemList);
6161

62+
bool popup_edit_commited = true;
6263
VBoxContainer *popup_editor_vb = nullptr;
6364
Popup *popup_editor = nullptr;
6465
LineEdit *line_editor = nullptr;

scene/gui/popup.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
void Popup::_input_from_window(const Ref<InputEvent> &p_event) {
3939
if (get_flag(FLAG_POPUP) && p_event->is_action_pressed(SNAME("ui_cancel"), false, true)) {
40+
hide_reason = HIDE_REASON_CANCELED; // ESC pressed, mark as canceled unconditionally.
4041
_close_pressed();
4142
}
4243
Window::_input_from_window(p_event);
@@ -104,13 +105,18 @@ void Popup::_notification(int p_what) {
104105

105106
case NOTIFICATION_WM_CLOSE_REQUEST: {
106107
if (!is_in_edited_scene_root()) {
107-
hide_reason = HIDE_REASON_UNFOCUSED;
108+
if (hide_reason == HIDE_REASON_NONE) {
109+
hide_reason = HIDE_REASON_UNFOCUSED;
110+
}
108111
_close_pressed();
109112
}
110113
} break;
111114

112115
case NOTIFICATION_APPLICATION_FOCUS_OUT: {
113116
if (!is_in_edited_scene_root() && get_flag(FLAG_POPUP)) {
117+
if (hide_reason == HIDE_REASON_NONE) {
118+
hide_reason = HIDE_REASON_UNFOCUSED;
119+
}
114120
_close_pressed();
115121
}
116122
} break;
@@ -119,7 +125,9 @@ void Popup::_notification(int p_what) {
119125

120126
void Popup::_parent_focused() {
121127
if (popped_up && get_flag(FLAG_POPUP)) {
122-
hide_reason = HIDE_REASON_UNFOCUSED;
128+
if (hide_reason == HIDE_REASON_NONE) {
129+
hide_reason = HIDE_REASON_UNFOCUSED;
130+
}
123131
_close_pressed();
124132
}
125133
}

scene/gui/tree.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3152,8 +3152,12 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
31523152
}
31533153

31543154
void Tree::_text_editor_popup_modal_close() {
3155+
if (popup_edit_commited) {
3156+
return; // Already processed by LineEdit/TextEdit commit.
3157+
}
3158+
31553159
if (popup_editor->get_hide_reason() == Popup::HIDE_REASON_CANCELED) {
3156-
return;
3160+
return; // ESC pressed, app focus lost, or forced close from code.
31573161
}
31583162

31593163
if (value_editor->has_point(value_editor->get_local_mouse_position())) {
@@ -3172,9 +3176,18 @@ void Tree::_text_editor_popup_modal_close() {
31723176
}
31733177

31743178
void Tree::_text_editor_gui_input(const Ref<InputEvent> &p_event) {
3179+
if (popup_edit_commited) {
3180+
return; // Already processed by _text_editor_popup_modal_close
3181+
}
3182+
3183+
if (popup_editor->get_hide_reason() == Popup::HIDE_REASON_CANCELED) {
3184+
return; // ESC pressed, app focus lost, or forced close from code.
3185+
}
3186+
31753187
if (p_event->is_action_pressed("ui_text_newline_blank", true)) {
31763188
accept_event();
31773189
} else if (p_event->is_action_pressed("ui_text_newline")) {
3190+
popup_edit_commited = true; // End edit popup processing.
31783191
popup_editor->hide();
31793192
_apply_multiline_edit();
31803193
accept_event();
@@ -3205,6 +3218,15 @@ void Tree::_apply_multiline_edit() {
32053218
}
32063219

32073220
void Tree::_line_editor_submit(String p_text) {
3221+
if (popup_edit_commited) {
3222+
return; // Already processed by _text_editor_popup_modal_close
3223+
}
3224+
3225+
if (popup_editor->get_hide_reason() == Popup::HIDE_REASON_CANCELED) {
3226+
return; // ESC pressed, app focus lost, or forced close from code.
3227+
}
3228+
3229+
popup_edit_commited = true; // End edit popup processing.
32083230
popup_editor->hide();
32093231

32103232
if (!popup_edited_item) {
@@ -4072,6 +4094,7 @@ bool Tree::edit_selected(bool p_force_edit) {
40724094
if (!popup_editor->is_embedded()) {
40734095
popup_editor->set_content_scale_factor(popup_scale);
40744096
}
4097+
popup_edit_commited = false; // Start edit popup processing.
40754098
popup_editor->popup();
40764099
popup_editor->child_controls_changed();
40774100

@@ -4091,6 +4114,7 @@ bool Tree::edit_selected(bool p_force_edit) {
40914114
if (!popup_editor->is_embedded()) {
40924115
popup_editor->set_content_scale_factor(popup_scale);
40934116
}
4117+
popup_edit_commited = false; // Start edit popup processing.
40944118
popup_editor->popup();
40954119
popup_editor->child_controls_changed();
40964120

scene/gui/tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ class Tree : public Control {
479479

480480
VBoxContainer *popup_editor_vb = nullptr;
481481

482+
bool popup_edit_commited = true;
482483
Popup *popup_editor = nullptr;
483484
LineEdit *line_editor = nullptr;
484485
TextEdit *text_editor = nullptr;

0 commit comments

Comments
 (0)