[Bf-blender-cvs] [b7939a059f9] master: Undo: use low level API calls to enable font edit-mode

Campbell Barton noreply at git.blender.org
Fri Feb 26 06:33:16 CET 2021


Commit: b7939a059f9056ae57b4720a4c98dbe9025de407
Author: Campbell Barton
Date:   Fri Feb 26 16:30:07 2021 +1100
Branches: master
https://developer.blender.org/rBb7939a059f9056ae57b4720a4c98dbe9025de407

Undo: use low level API calls to enable font edit-mode

While I couldn't redo a bug in this case, it's possible for the
active object to become out of sync in rare cases,
so best use these functions.

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

M	source/blender/editors/curve/editfont_undo.c

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

diff --git a/source/blender/editors/curve/editfont_undo.c b/source/blender/editors/curve/editfont_undo.c
index 8f7eb19dfe8..a305a997d50 100644
--- a/source/blender/editors/curve/editfont_undo.c
+++ b/source/blender/editors/curve/editfont_undo.c
@@ -23,6 +23,8 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "CLG_log.h"
+
 #include "BLI_array_utils.h"
 #include "BLI_utildefines.h"
 
@@ -39,6 +41,7 @@
 
 #include "ED_curve.h"
 #include "ED_object.h"
+#include "ED_undo.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -53,6 +56,9 @@
 #  define ARRAY_CHUNK_SIZE 32
 #endif
 
+/** Only needed this locally. */
+static CLG_LogRef LOG = {"ed.undo.font"};
+
 /* -------------------------------------------------------------------- */
 /** \name Undo Conversion
  * \{ */
@@ -364,15 +370,22 @@ static void font_undosys_step_decode(struct bContext *C,
                                      const eUndoStepDir UNUSED(dir),
                                      bool UNUSED(is_final))
 {
-  /* TODO(campbell): undo_system: use low-level API to set mode. */
-  ED_object_mode_set_ex(C, OB_MODE_EDIT, false, NULL);
-  BLI_assert(font_undosys_poll(C));
 
   FontUndoStep *us = (FontUndoStep *)us_p;
   Object *obedit = us->obedit_ref.ptr;
+
+  /* Pass in an array of 1 (typically used for multi-object edit-mode). */
+  ED_undo_object_editmode_restore_helper(C, &obedit, 1, sizeof(Object *));
+
   Curve *cu = obedit->data;
   undofont_to_editfont(&us->data, cu);
   DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY);
+
+  ED_undo_object_set_active_or_warn(
+      CTX_data_scene(C), CTX_data_view_layer(C), obedit, us_p->name, &LOG);
+
+  BLI_assert(font_undosys_poll(C));
+
   cu->editfont->needs_flush_to_id = 1;
   bmain->is_memfile_undo_flush_needed = true;
   WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);



More information about the Bf-blender-cvs mailing list