gaphor / gaphor

Gaphor is the simple modeling tool
https://gaphor.org
1.87k stars 200 forks source link

Delete + undo does not work #631

Closed amolenaar closed 3 years ago

amolenaar commented 3 years ago

Describe the bug

Deleting a model element and then performing an undo action causes the diagram item to be shown, but it's not backed by a model element.

To Reproduce Steps to reproduce the behavior:

  1. Create a Class item
  2. Select it and delete it
  3. Undo (ctrl-z)
  4. A box is drawn, but no content. E.i. the model element is missing

Expected behavior

It to work properly.

Version Version of Gaphor: 2.2.1

amolenaar commented 3 years ago

There are two problem scenario's.

Overtake events

When undoing:

Bi-directional associations

When this is undone, first it's trying to create a relation with an element that no longer exists.

amolenaar commented 3 years ago

The solution proved simpler. The undo events need to be ordered: create elements, then set properties and lastly unlink (remove) elements. This is basically the same order we use for loading models and copy/paste functionality.

The options above has the big disadvantage that events could only be sent after all effects were applied. This made it hard to undo the effects. Now undoing can still be done close to where the event happened. The undo mechanism only had to be a little smarter.