summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scene/gui/line_edit.cpp14
-rw-r--r--scene/gui/line_edit.h2
2 files changed, 16 insertions, 0 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index ab6f80bfa9..85287813e0 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -970,6 +970,8 @@ void LineEdit::undo() {
undo_stack_pos = undo_stack_pos->prev();
TextOperation op = undo_stack_pos->get();
text = op.text;
+ cached_width = op.cached_width;
+ window_pos = op.window_pos;
set_cursor_position(op.cursor_pos);
if (expand_to_text_length)
@@ -988,6 +990,8 @@ void LineEdit::redo() {
undo_stack_pos = undo_stack_pos->next();
TextOperation op = undo_stack_pos->get();
text = op.text;
+ cached_width = op.cached_width;
+ window_pos = op.window_pos;
set_cursor_position(op.cursor_pos);
if (expand_to_text_length)
@@ -1169,6 +1173,10 @@ void LineEdit::delete_char() {
set_cursor_position(get_cursor_position() - 1);
+ if (align == ALIGN_CENTER || align == ALIGN_RIGHT) {
+ window_pos = CLAMP(window_pos - 1, 0, text.length() - 1);
+ }
+
_text_changed();
}
@@ -1196,6 +1204,10 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) {
window_pos = cursor_pos;
}
+ if (align == ALIGN_CENTER || align == ALIGN_RIGHT) {
+ window_pos = CLAMP(window_pos - (p_to_column - p_from_column), 0, text.length() - 1);
+ }
+
if (!text_changed_dirty) {
if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_text_changed");
@@ -1677,7 +1689,9 @@ void LineEdit::_clear_undo_stack() {
void LineEdit::_create_undo_state() {
TextOperation op;
op.text = text;
+ op.cached_width = cached_width;
op.cursor_pos = cursor_pos;
+ op.window_pos = window_pos;
undo_stack.push_back(op);
}
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index 3424131dad..ebe49091eb 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -106,6 +106,8 @@ private:
struct TextOperation {
int cursor_pos;
+ int window_pos;
+ int cached_width;
String text;
};
List<TextOperation> undo_stack;