Skip to content

Commit f6e29ad

Browse files
authored
Merge pull request #37846 from CaptainProton42/text-edit-undo-stack-size
Add "undo_max_stack_size" property to TextEdit
2 parents 58435b0 + 4a82390 commit f6e29ad

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

scene/gui/text_edit.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -6215,6 +6215,10 @@ void TextEdit::_push_current_op() {
62156215
current_op.type = TextOperation::TYPE_NONE;
62166216
current_op.text = "";
62176217
current_op.chain_forward = false;
6218+
6219+
if (undo_stack.size() > undo_stack_max_size) {
6220+
undo_stack.pop_front();
6221+
}
62186222
}
62196223

62206224
void TextEdit::set_indent_using_spaces(const bool p_use_spaces) {
@@ -7239,6 +7243,8 @@ void TextEdit::_bind_methods() {
72397243

72407244
GLOBAL_DEF("gui/timers/text_edit_idle_detect_sec", 3);
72417245
ProjectSettings::get_singleton()->set_custom_property_info("gui/timers/text_edit_idle_detect_sec", PropertyInfo(Variant::FLOAT, "gui/timers/text_edit_idle_detect_sec", PROPERTY_HINT_RANGE, "0,10,0.01,or_greater")); // No negative numbers.
7246+
GLOBAL_DEF("gui/common/text_edit_undo_stack_max_size", 1024);
7247+
ProjectSettings::get_singleton()->set_custom_property_info("gui/common/text_edit_undo_stack_max_size", PropertyInfo(Variant::INT, "gui/common/text_edit_undo_stack_max_size", PROPERTY_HINT_RANGE, "0,10000,1,or_greater")); // No negative numbers.
72427248
}
72437249

72447250
TextEdit::TextEdit() {
@@ -7318,6 +7324,7 @@ TextEdit::TextEdit() {
73187324

73197325
current_op.type = TextOperation::TYPE_NONE;
73207326
undo_enabled = true;
7327+
undo_stack_max_size = GLOBAL_GET("gui/common/text_edit_undo_stack_max_size");
73217328
undo_stack_pos = nullptr;
73227329
setting_text = false;
73237330
last_dblclk = 0;

scene/gui/text_edit.h

+1
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ class TextEdit : public Control {
306306

307307
List<TextOperation> undo_stack;
308308
List<TextOperation>::Element *undo_stack_pos;
309+
int undo_stack_max_size;
309310

310311
void _clear_redo();
311312
void _do_text_op(const TextOperation &p_op, bool p_reverse);

0 commit comments

Comments
 (0)