Fix undoing pasted data
* Connected items are no longer unlinked directly * Connectors are smarter at finding out the diagram The latter is needed, since a diagram can be set to None before connections are actually removed from the diagram.
This commit is contained in:
parent
1413928833
commit
aa7e1d34d8
@ -105,14 +105,7 @@ class Presentation(Matrices, Element, Generic[S]):
|
||||
self.parent.matrix_i2c.remove_handler(self._on_matrix_changed)
|
||||
|
||||
if diagram := self._original_diagram:
|
||||
connecting_items = [
|
||||
cinfo.item
|
||||
for cinfo in diagram.connections.get_connections(connected=self)
|
||||
]
|
||||
|
||||
diagram.connections.remove_connections_to_item(self)
|
||||
for item in connecting_items:
|
||||
item.unlink()
|
||||
self._original_diagram = None
|
||||
super().inner_unlink(UnlinkEvent(self, diagram=diagram))
|
||||
|
||||
|
@ -71,7 +71,15 @@ class BaseConnector:
|
||||
) -> None:
|
||||
self.element = element
|
||||
self.line = line
|
||||
self.diagram: Diagram = element.diagram
|
||||
|
||||
# Try to find the diagram. Any diagram can be None, when called while an element is unlinking
|
||||
assert (
|
||||
element.diagram is line.diagram
|
||||
or element.diagram is None
|
||||
or line.diagram is None
|
||||
)
|
||||
self.diagram: Diagram = element.diagram or line.diagram
|
||||
assert self.diagram
|
||||
|
||||
def get_connected(self, handle: Handle) -> Presentation[Element] | None:
|
||||
"""Get item connected to a handle."""
|
||||
|
@ -182,8 +182,8 @@ def test_commentline_element_unlink(create, diagram):
|
||||
|
||||
assert clazz not in diagram.ownedPresentation
|
||||
assert not clazz.diagram
|
||||
assert line not in diagram.ownedPresentation
|
||||
assert not line.diagram
|
||||
assert line in diagram.ownedPresentation
|
||||
assert line.diagram
|
||||
assert not comment.subject.annotatedElement
|
||||
assert len(clazz_subject.comment) == 0
|
||||
|
||||
|
@ -150,5 +150,5 @@ def test_remove_connected_items_on_unlink(create, diagram):
|
||||
class_a_item.subject.unlink()
|
||||
|
||||
assert class_a_item not in diagram.ownedPresentation
|
||||
assert association_item not in diagram.ownedPresentation
|
||||
assert association_item in diagram.ownedPresentation
|
||||
assert class_b_item in diagram.ownedPresentation
|
||||
|
@ -63,7 +63,7 @@ def test_class_association_undo_redo(event_manager, element_factory, undo_manage
|
||||
assert undo_manager.can_undo()
|
||||
|
||||
for _i in range(3):
|
||||
assert 8 == len(diagram.connections.solver.constraints)
|
||||
assert 9 == len(diagram.connections.solver.constraints)
|
||||
|
||||
undo_manager.undo_transaction()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user