Undo Issue on backend load


When we load diagram, CompoundEdits count must be zero so that undo will not be triggered. However, sometimes CoumpoundEdits are not being cleared due to which we are able to undo as soon as the diagram is rendered.


As a process of investigation, we found that in the below code LayoutCompleted property is being set to true at some unknown point. As a result, clear method in UndoManager is not getting invoked.

Code (in DiagramPanel)

private void DoUpdateDiagramBounds() {
      // in case some are left over or because of undo/redo
      if (this.SkipsNextUpdateDiagramBounds) {
        this.SkipsNextUpdateDiagramBounds = false;
        Diagram.InvokeLater(this, DoUpdateDiagramBounds);
      try {
        this.DiagramBounds = ComputeDiagramBounds();
      } catch (Exception) {
      //Diagram.Debug(this.UpdateDiagramBoundsReason + " " + Diagram.Str(this.DiagramBounds) + this.LayoutCompleted.ToString() + " " + this.InitialLayoutCompleted.ToString());
      this.UpdateDiagramBoundsReason = null;
      // if LayoutCompleted is true, this is the first time we've computed the diagram bounds since finishing a layout;
      // only raise the Diagram.InitialLayoutCompleted and Diagram.LayoutCompleted events after computing new diagram bounds
      if (this.LayoutCompleted && this.Diagram != null) {
        if (!this.InitialLayoutCompleted) {
          this.InitialLayoutCompleted = true;
          this.IsVirtualizing = true;
      this.LayoutCompleted = false;

When replacing the Diagram.Model, it effectively is also replacing its UndoManager. So it doesn’t make sense to have a transaction ongoing when replacing the model.

So I am guessing that the problem is that you have started a transaction when replacing the diagram’s model.