Preserve selection when focusing SpinBox
This commit is contained in:
parent
cb19b81374
commit
c377bffaa1
|
@ -1400,6 +1400,26 @@ void LineEdit::set_text(String p_text) {
|
|||
scroll_offset = 0;
|
||||
}
|
||||
|
||||
void LineEdit::set_text_with_selection(const String &p_text) {
|
||||
Selection selection_copy = selection;
|
||||
|
||||
clear_internal();
|
||||
append_at_cursor(p_text);
|
||||
_create_undo_state();
|
||||
|
||||
if (expand_to_text_length) {
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
||||
int tlen = text.length();
|
||||
selection = selection_copy;
|
||||
selection.begin = MIN(selection.begin, tlen);
|
||||
selection.end = MIN(selection.end, tlen);
|
||||
selection.cursor_start = MIN(selection.cursor_start, tlen);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void LineEdit::clear() {
|
||||
clear_internal();
|
||||
_text_changed();
|
||||
|
|
|
@ -208,6 +208,7 @@ public:
|
|||
void delete_char();
|
||||
void delete_text(int p_from_column, int p_to_column);
|
||||
void set_text(String p_text);
|
||||
void set_text_with_selection(const String &p_text); // Set text, while preserving selection.
|
||||
String get_text() const;
|
||||
void set_placeholder(String p_text);
|
||||
String get_placeholder() const;
|
||||
|
|
|
@ -50,7 +50,7 @@ void SpinBox::_value_changed(double) {
|
|||
}
|
||||
}
|
||||
|
||||
line_edit->set_text(value);
|
||||
line_edit->set_text_with_selection(value);
|
||||
}
|
||||
|
||||
void SpinBox::_text_entered(const String &p_string) {
|
||||
|
|
Loading…
Reference in New Issue