Skip to content

Undoing the deletion of a connected block does not restore its outer connections #9616

@maxherrmann

Description

@maxherrmann

Check for duplicates

  • I have searched for similar issues before opening a new one.

Description

When undoing the deletion of a connected block, its outer connections (ConnectionType.PREVIOUS_STATEMENT or ConnectionType.OUTPUT_VALUE) are not restored. This results in the block becoming disconnected and bumped away instead.

The issue was introduced in Blockly 12.4.0 as part of 52d935c:

blockly/core/connection.ts

Lines 294 to 302 in 52d935c

if (
eventUtils.isEnabled() &&
!childConnection.getSourceBlock().isDeadOrDying()
) {
event = new (eventUtils.get(EventType.BLOCK_MOVE))(
childConnection.getSourceBlock(),
) as BlockMove;
event.setReason(['disconnect']);
}

The added check for the block being dead or dying in Connection.disconnectInternal() prevents the BlockMove event with reason "disconnect" from being constructed and fired. This, in turn, results in it not being recorded and added to the active event group.

childConnection.getSourceBlock().isDeadOrDying() is always true in this case, as Block.disposing has already been set to true here earlier when Block.dipose() was invoked.

When undoing the deletion, the block’s outer connections are not properly restored because the disconnection event was never recorded and is thus not part of the undo stack.

Reproduction steps

  1. Add a controls_if block to the workspace.
  2. Add any other block to the workspace.
  3. Connect the block to the controls_if block anywhere.
  4. Delete the block.
  5. Undo once.

→ Observe that the restored block is not connected to the controls_if block.

Priority

This is a major issue, as it effectively breaks undoing most block deletions in Blockly 12.4.0 and higher.

A fix for this should be relatively straightforward and would involve improving the changes introduced to Connection.disconnectInternal() in 52d935c, while also keeping #8455 fixed.

Stack trace

Screenshots

No response

Browsers

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugDescribes why the code or behaviour is wrong

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions