From 8e7f5c86288194048abd66206cd4b33958132c73 Mon Sep 17 00:00:00 2001 From: Michael Alexsander Silva Dias Date: Sat, 20 Apr 2019 18:22:37 -0300 Subject: [PATCH] Fix 'LineEdit' contents not ending before the clear button if no right icon was set Fixes #28242. (cherry picked from commit d84acb98d0863ec142a9496bd229e7163deaefe8) --- scene/gui/line_edit.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 83e028e90e..9d1f749fcc 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1159,8 +1159,10 @@ void LineEdit::set_cursor_position(int p_pos) { } else if (cursor_pos > window_pos) { /* Adjust window if cursor goes too much to the right */ int window_width = get_size().width - style->get_minimum_size().width; - if (right_icon.is_valid()) { - window_width -= right_icon->get_width(); + bool display_clear_icon = !text.empty() && is_editable() && clear_button_enabled; + if (right_icon.is_valid() || display_clear_icon) { + Ref r_icon = display_clear_icon ? Control::get_icon("clear") : right_icon; + window_width -= r_icon->get_width(); } if (window_width < 0)