Skip to content

Commit 3c2b8b4

Browse files
authored
fix: reset initial connections before storing new ones (#9982)
* fix: reset initial connections before storing new ones * chore: reset state in endDrag
1 parent ef88be2 commit 3c2b8b4

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

packages/blockly/core/dragging/block_drag_strategy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ export class BlockDragStrategy implements IDragStrategy {
485485
* the initial connection pair is also used as the first connection candidate.
486486
*/
487487
private storeInitialConnections(healStack: boolean) {
488+
this.startParentConn = null;
489+
this.startChildConn = null;
488490
// Prioritize the block's parent connection (output or previous) if one exists.
489491
let localParentConn: RenderedConnection | null = null;
490492
let parentTargetConn: RenderedConnection | null = null;
@@ -914,6 +916,10 @@ export class BlockDragStrategy implements IDragStrategy {
914916
}
915917

916918
this.allConnectionPairs = [];
919+
this.startParentConn = null;
920+
this.startChildConn = null;
921+
this.connectionCandidate = null;
922+
this.dragging = false;
917923
}
918924

919925
/** Disposes of any state at the end of the drag. */

packages/blockly/tests/mocha/keyboard_movement_test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,61 @@ suite('Keyboard-driven movement', function () {
779779
assert.isFalse(ifBlock.isEnabled());
780780
});
781781

782+
test('Cancel after committed keyboard move does not throw', function () {
783+
// if block with repeat block in next connection
784+
const json = {
785+
'blocks': {
786+
'languageVersion': 0,
787+
'blocks': [
788+
{
789+
'type': 'controls_if',
790+
'id': 'ifBlock',
791+
'x': 25,
792+
'y': 10,
793+
'next': {
794+
'block': {
795+
'type': 'controls_repeat_ext',
796+
'id': 'repeatBlock',
797+
'inputs': {
798+
'TIMES': {
799+
'shadow': {
800+
'type': 'math_number',
801+
'fields': {
802+
'NUM': 10,
803+
},
804+
},
805+
},
806+
},
807+
},
808+
},
809+
},
810+
],
811+
},
812+
};
813+
this.workspace.clear();
814+
Blockly.serialization.workspaces.load(json, this.workspace);
815+
const ifBlock = this.workspace.getBlockById('ifBlock');
816+
const repeatBlock = this.workspace.getBlockById('repeatBlock');
817+
818+
// Move the if block down twice so it connects to the repeat block statement input.
819+
Blockly.getFocusManager().focusNode(ifBlock);
820+
startMove(this.workspace);
821+
moveDown(this.workspace);
822+
moveDown(this.workspace);
823+
endMove(this.workspace);
824+
825+
assert.strictEqual(ifBlock.getParent(), repeatBlock);
826+
827+
// Start a second keyboard move and cancel before committing.
828+
assert.doesNotThrow(() => {
829+
Blockly.getFocusManager().focusNode(ifBlock);
830+
startMove(this.workspace);
831+
moveUp(this.workspace);
832+
moveUp(this.workspace);
833+
cancelMove(this.workspace);
834+
});
835+
});
836+
782837
suite('Statement move tests', function () {
783838
// Clear the workspace and load start blocks.
784839
setup(function () {

0 commit comments

Comments
 (0)