瀏覽代碼

Cleanup in undo in TextEdit and LineEdit

Sofox 1 年之前
父節點
當前提交
a1a5c87f9e
共有 2 個文件被更改,包括 6 次插入10 次删除
  1. 5 9
      scene/gui/line_edit.cpp
  2. 1 1
      scene/gui/text_edit.cpp

+ 5 - 9
scene/gui/line_edit.cpp

@@ -1208,13 +1208,12 @@ void LineEdit::undo() {
 		return;
 	}
 
+	if (!has_undo()) {
+		return;
+	}
+
 	if (undo_stack_pos == nullptr) {
-		if (undo_stack.size() <= 1) {
-			return;
-		}
 		undo_stack_pos = undo_stack.back();
-	} else if (undo_stack_pos == undo_stack.front()) {
-		return;
 	}
 
 	deselect();
@@ -1234,10 +1233,7 @@ void LineEdit::redo() {
 		return;
 	}
 
-	if (undo_stack_pos == nullptr) {
-		return;
-	}
-	if (undo_stack_pos == undo_stack.back()) {
+	if (!has_redo()) {
 		return;
 	}
 

+ 1 - 1
scene/gui/text_edit.cpp

@@ -4024,7 +4024,7 @@ void TextEdit::redo() {
 	}
 	_push_current_op();
 
-	if (undo_stack_pos == nullptr) {
+	if (!has_redo()) {
 		return; // Nothing to do.
 	}