[Bf-blender-cvs] [0f589f8d3cc] master: Fix T94115: Selecting current action in undo history undoes all

Campbell Barton noreply at git.blender.org
Thu Dec 16 13:41:54 CET 2021


Commit: 0f589f8d3ccc883704a692d8d22fb3860f12d695
Author: Campbell Barton
Date:   Thu Dec 16 23:31:20 2021 +1100
Branches: master
https://developer.blender.org/rB0f589f8d3ccc883704a692d8d22fb3860f12d695

Fix T94115: Selecting current action in undo history undoes all

When selecting the current undo step there is no need to do anything.

Fix and minor refactor to de-duplicate refreshing after running
undo/redo & undo history.

===================================================================

M	source/blender/blenkernel/intern/undo_system.c
M	source/blender/editors/undo/ed_undo.c

===================================================================

diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index 743ae91f6f7..3e263fafe28 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -819,6 +819,9 @@ void BKE_undosys_step_load_from_index(UndoStack *ustack, bContext *C, const int
 {
   UndoStep *us_target = BLI_findlink(&ustack->steps, index);
   BLI_assert(us_target->skip == false);
+  if (us_target == ustack->step_active) {
+    return;
+  }
   BKE_undosys_step_load_data(ustack, C, us_target);
 }
 
diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c
index ca8b86d525d..aca99f81e7b 100644
--- a/source/blender/editors/undo/ed_undo.c
+++ b/source/blender/editors/undo/ed_undo.c
@@ -374,6 +374,9 @@ static int ed_undo_step_by_index(bContext *C, const int undo_index, ReportList *
 
   wmWindowManager *wm = CTX_wm_manager(C);
   const int active_step_index = BLI_findindex(&wm->undo_stack->steps, wm->undo_stack->step_active);
+  if (undo_index == active_step_index) {
+    return OPERATOR_CANCELLED;
+  }
   const enum eUndoStepDir undo_dir = (undo_index < active_step_index) ? STEP_UNDO : STEP_REDO;
 
   CLOG_INFO(&LOG,
@@ -494,17 +497,28 @@ UndoStack *ED_undo_stack_get(void)
 /** \name Undo, Undo Push & Redo Operators
  * \{ */
 
+/**
+ * Refresh to run after user activated undo/redo actions.
+ */
+static void ed_undo_refresh_for_op(bContext *C)
+{
+  /* The "last operator" should disappear, later we can tie this with undo stack nicer. */
+  WM_operator_stack_clear(CTX_wm_manager(C));
+
+  /* Keep button under the cursor active. */
+  WM_event_add_mousemove(CTX_wm_window(C));
+
+  ED_outliner_select_sync_from_all_tag(C);
+}
+
 static int ed_undo_exec(bContext *C, wmOperator *op)
 {
   /* "last operator" should disappear, later we can tie this with undo stack nicer */
   WM_operator_stack_clear(CTX_wm_manager(C));
   int ret = ed_undo_step_direction(C, STEP_UNDO, op->reports);
   if (ret & OPERATOR_FINISHED) {
-    /* Keep button under the cursor active. */
-    WM_event_add_mousemove(CTX_wm_window(C));
+    ed_undo_refresh_for_op(C);
   }
-
-  ED_outliner_select_sync_from_all_tag(C);
   return ret;
 }
 
@@ -529,11 +543,8 @@ static int ed_redo_exec(bContext *C, wmOperator *op)
 {
   int ret = ed_undo_step_direction(C, STEP_REDO, op->reports);
   if (ret & OPERATOR_FINISHED) {
-    /* Keep button under the cursor active. */
-    WM_event_add_mousemove(CTX_wm_window(C));
+    ed_undo_refresh_for_op(C);
   }
-
-  ED_outliner_select_sync_from_all_tag(C);
   return ret;
 }
 
@@ -823,10 +834,13 @@ static int undo_history_exec(bContext *C, wmOperator *op)
   PropertyRNA *prop = RNA_struct_find_property(op->ptr, "item");
   if (RNA_property_is_set(op->ptr, prop)) {
     int item = RNA_property_int_get(op->ptr, prop);
-    WM_operator_stack_clear(CTX_wm_manager(C));
-    ed_undo_step_by_index(C, item, op->reports);
-    WM_event_add_notifier(C, NC_WINDOW, NULL);
-    return OPERATOR_FINISHED;
+    const int ret = ed_undo_step_by_index(C, item, op->reports);
+    if (ret & OPERATOR_FINISHED) {
+      ed_undo_refresh_for_op(C);
+
+      WM_event_add_notifier(C, NC_WINDOW, NULL);
+      return OPERATOR_FINISHED;
+    }
   }
   return OPERATOR_CANCELLED;
 }



More information about the Bf-blender-cvs mailing list