Preserve selection when focusing SpinBox
This commit is contained in:
parent
37d1dfef9d
commit
968c5f6247
@ -1527,6 +1527,22 @@ void LineEdit::set_text(String p_text) {
|
|||||||
scroll_offset = 0.0;
|
scroll_offset = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LineEdit::set_text_with_selection(const String &p_text) {
|
||||||
|
Selection selection_copy = selection;
|
||||||
|
|
||||||
|
clear_internal();
|
||||||
|
insert_text_at_caret(p_text);
|
||||||
|
_create_undo_state();
|
||||||
|
|
||||||
|
int tlen = text.length();
|
||||||
|
selection = selection_copy;
|
||||||
|
selection.begin = MIN(selection.begin, tlen);
|
||||||
|
selection.end = MIN(selection.end, tlen);
|
||||||
|
selection.start_column = MIN(selection.start_column, tlen);
|
||||||
|
|
||||||
|
queue_redraw();
|
||||||
|
}
|
||||||
|
|
||||||
void LineEdit::set_text_direction(Control::TextDirection p_text_direction) {
|
void LineEdit::set_text_direction(Control::TextDirection p_text_direction) {
|
||||||
ERR_FAIL_COND((int)p_text_direction < -1 || (int)p_text_direction > 3);
|
ERR_FAIL_COND((int)p_text_direction < -1 || (int)p_text_direction > 3);
|
||||||
if (text_direction != p_text_direction) {
|
if (text_direction != p_text_direction) {
|
||||||
|
@ -283,6 +283,7 @@ public:
|
|||||||
|
|
||||||
void set_text(String p_text);
|
void set_text(String p_text);
|
||||||
String get_text() const;
|
String get_text() const;
|
||||||
|
void set_text_with_selection(const String &p_text); // Set text, while preserving selection.
|
||||||
|
|
||||||
void set_text_direction(TextDirection p_text_direction);
|
void set_text_direction(TextDirection p_text_direction);
|
||||||
TextDirection get_text_direction() const;
|
TextDirection get_text_direction() const;
|
||||||
|
@ -54,7 +54,7 @@ void SpinBox::_update_text() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
line_edit->set_text(value);
|
line_edit->set_text_with_selection(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpinBox::_text_submitted(const String &p_string) {
|
void SpinBox::_text_submitted(const String &p_string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user