From 57b616fb218d446d3d770d6d3e2c21e468df8966 Mon Sep 17 00:00:00 2001 From: ConteZero Date: Sun, 3 Apr 2022 10:07:02 +0200 Subject: [PATCH] Fix Right-Click clearing selection --- scene/gui/line_edit.cpp | 6 ++++-- scene/gui/line_edit.h | 1 + scene/gui/text_edit.cpp | 6 ++++-- scene/gui/text_edit.h | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 81de06386f0..34e9ef830ed 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -53,6 +53,7 @@ void LineEdit::_gui_input(Ref p_event) { if (b.is_valid()) { if (b->is_pressed() && b->get_button_index() == BUTTON_RIGHT && context_menu_enabled) { + popup_show = true; if (editable) { menu->set_item_disabled(menu->get_item_index(MENU_UNDO), !has_undo()); menu->set_item_disabled(menu->get_item_index(MENU_REDO), !has_redo()); @@ -62,7 +63,6 @@ void LineEdit::_gui_input(Ref p_event) { menu->set_size(Vector2(1, 1)); menu->set_scale(get_global_transform().get_scale()); menu->popup(); - grab_focus(); accept_event(); return; } @@ -608,6 +608,7 @@ void LineEdit::_gui_input(Ref p_event) { } break; case KEY_MENU: { if (context_menu_enabled) { + popup_show = true; if (editable) { menu->set_item_disabled(menu->get_item_index(MENU_UNDO), !has_undo()); menu->set_item_disabled(menu->get_item_index(MENU_REDO), !has_redo()); @@ -1040,9 +1041,10 @@ void LineEdit::_notification(int p_what) { OS::get_singleton()->hide_virtual_keyboard(); } - if (deselect_on_focus_loss_enabled) { + if (deselect_on_focus_loss_enabled && !popup_show) { deselect(); } + popup_show = false; } break; case MainLoop::NOTIFICATION_OS_IME_UPDATE: { if (has_focus()) { diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 19c5c60e28f..0171bd9b80d 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -76,6 +76,7 @@ private: bool selecting_enabled; bool deselect_on_focus_loss_enabled; + bool popup_show = false; bool context_menu_enabled; PopupMenu *menu; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 53fa404d0e6..8c32569790e 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1897,9 +1897,10 @@ void TextEdit::_notification(int p_what) { OS::get_singleton()->hide_virtual_keyboard(); } - if (deselect_on_focus_loss_enabled) { + if (deselect_on_focus_loss_enabled && !popup_show) { deselect(); } + popup_show = false; } break; case MainLoop::NOTIFICATION_OS_IME_UPDATE: { if (has_focus()) { @@ -2652,6 +2653,7 @@ void TextEdit::_gui_input(const Ref &p_gui_input) { } } + popup_show = true; if (!readonly) { menu->set_item_disabled(menu->get_item_index(MENU_UNDO), !has_undo()); menu->set_item_disabled(menu->get_item_index(MENU_REDO), !has_redo()); @@ -2661,7 +2663,6 @@ void TextEdit::_gui_input(const Ref &p_gui_input) { menu->set_size(Vector2(1, 1)); menu->set_scale(get_global_transform().get_scale()); menu->popup(); - grab_focus(); } } else { if (mb->get_button_index() == BUTTON_LEFT) { @@ -3963,6 +3964,7 @@ void TextEdit::_gui_input(const Ref &p_gui_input) { case KEY_MENU: { if (context_menu_enabled) { + popup_show = true; if (!readonly) { menu->set_item_disabled(menu->get_item_index(MENU_UNDO), !has_undo()); menu->set_item_disabled(menu->get_item_index(MENU_REDO), !has_redo()); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index e6a4f15feaa..590d38ad358 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -438,6 +438,7 @@ private: bool selecting_enabled; bool deselect_on_focus_loss_enabled; + bool popup_show = false; bool context_menu_enabled; bool shortcut_keys_enabled;