@@ -40,7 +40,7 @@ Size2 SpinBox::get_minimum_size() const {
4040 return ms;
4141}
4242
43- void SpinBox::_update_text (bool p_keep_line_edit ) {
43+ void SpinBox::_update_text (bool p_only_update_if_value_changed ) {
4444 double step = get_step ();
4545 if (use_custom_arrow_step && custom_arrow_step != 0.0 ) {
4646 step = custom_arrow_step;
@@ -50,6 +50,11 @@ void SpinBox::_update_text(bool p_keep_line_edit) {
5050 value = TS->format_number (value);
5151 }
5252
53+ if (p_only_update_if_value_changed && value == last_text_value) {
54+ return ;
55+ }
56+ last_text_value = value;
57+
5358 if (!line_edit->is_editing ()) {
5459 if (!prefix.is_empty ()) {
5560 value = prefix + " " + value;
@@ -58,17 +63,12 @@ void SpinBox::_update_text(bool p_keep_line_edit) {
5863 value += " " + suffix;
5964 }
6065 }
61-
62- if (p_keep_line_edit && value == last_updated_text && value != line_edit->get_text ()) {
63- return ;
64- }
65-
6666 line_edit->set_text_with_selection (value);
67- last_updated_text = value;
6867}
6968
7069void SpinBox::_text_submitted (const String &p_string) {
7170 if (p_string.is_empty ()) {
71+ _update_text ();
7272 return ;
7373 }
7474
@@ -288,14 +288,12 @@ void SpinBox::_line_edit_editing_toggled(bool p_toggled_on) {
288288 line_edit->select_all ();
289289 }
290290 } else {
291- // Discontinue because the focus_exit was caused by canceling or the text is empty.
292291 if (Input::get_singleton ()->is_action_pressed (" ui_cancel" ) || line_edit->get_text ().is_empty ()) {
293- _update_text ();
294- return ;
292+ _update_text (); // Revert text if editing was canceled.
293+ } else {
294+ _update_text (true ); // Update text in case value was changed this frame (e.g. on `focus_exited`).
295+ _text_submitted (line_edit->get_text ());
295296 }
296-
297- line_edit->deselect ();
298- _text_submitted (line_edit->get_text ());
299297 }
300298}
301299
0 commit comments