Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Right-Click clearing selection #59827

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions scene/gui/line_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void LineEdit::_gui_input(Ref<InputEvent> 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());
Expand All @@ -62,7 +63,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
menu->set_size(Vector2(1, 1));
menu->set_scale(get_global_transform().get_scale());
menu->popup();
grab_focus();
accept_event();
return;
}
Expand Down Expand Up @@ -608,6 +608,7 @@ void LineEdit::_gui_input(Ref<InputEvent> 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());
Expand Down Expand Up @@ -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()) {
Expand Down
1 change: 1 addition & 0 deletions scene/gui/line_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class LineEdit : public Control {

bool selecting_enabled;
bool deselect_on_focus_loss_enabled;
bool popup_show = false;

bool context_menu_enabled;
PopupMenu *menu;
Expand Down
6 changes: 4 additions & 2 deletions scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -2652,6 +2653,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &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());
Expand All @@ -2661,7 +2663,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &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) {
Expand Down Expand Up @@ -3963,6 +3964,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &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());
Expand Down
1 change: 1 addition & 0 deletions scene/gui/text_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ class TextEdit : public Control {

bool selecting_enabled;
bool deselect_on_focus_loss_enabled;
bool popup_show = false;

bool context_menu_enabled;
bool shortcut_keys_enabled;
Expand Down