diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 80a4bb1e052..b9b8b7fda00 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -550,8 +550,22 @@ void LineEdit::_notification(int p_what) { set_cursor_pos( get_cursor_pos() ); } break; + case MainLoop::NOTIFICATION_WM_FOCUS_IN: { + window_has_focus = true; + draw_caret = true; + update(); + } break; + case MainLoop::NOTIFICATION_WM_FOCUS_OUT: { + window_has_focus = false; + draw_caret = false; + update(); + } break; case NOTIFICATION_DRAW: { + if ((!has_focus() && !menu->has_focus()) || !window_has_focus) { + draw_caret = false; + } + int width,height; Size2 size=get_size(); @@ -644,6 +658,10 @@ void LineEdit::_notification(int p_what) { } break; case NOTIFICATION_FOCUS_ENTER: { + if (!caret_blink_enabled) { + draw_caret = true; + } + if (OS::get_singleton()->has_virtual_keyboard()) OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect()); @@ -1228,6 +1246,7 @@ LineEdit::LineEdit() { cached_width = 0; cursor_pos=0; window_pos=0; + window_has_focus=true; max_length = 0; pass=false; diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index bcacb441ce3..e458c47ff48 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -90,6 +90,7 @@ private: Timer *caret_blink_timer; bool caret_blink_enabled; bool draw_caret; + bool window_has_focus; void shift_selection_check_pre(bool); void shift_selection_check_post(bool);