From 1b6d116dfbf5c93a5bf60b725075e7893bc97dfb Mon Sep 17 00:00:00 2001 From: Tony-Goat <70238376+Tony-Goat@users.noreply.github.com> Date: Tue, 25 Aug 2020 15:58:03 -0600 Subject: [PATCH] Updated LineEdit to address #41278 Updated set_max_length() function to actually pull a substring of the current text so it's not all thrown away when the new max length is shorter than the current length. (cherry picked from commit 71febfd6e2f6187fcc106ce715124cf173bfa0b8) --- scene/gui/line_edit.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 805297d5ac3..7474e885c53 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1263,7 +1263,12 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) { void LineEdit::set_text(String p_text) { clear_internal(); - append_at_cursor(p_text); + + if (p_text.length() > max_length) { + append_at_cursor(p_text.substr(0, max_length)); + } else { + append_at_cursor(p_text); + } if (expand_to_text_length) { minimum_size_changed();