Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,28 @@ export class Navigation {
return connection as Blockly.RenderedConnection;
}

// 2. Connect statement blocks to next connection.
// 2. Connect statement blocks to next connection. Only return a next
// connection to which the statement block can actually connect; some
// may be ineligible because they are e.g. in the middle of an immovable
// stack.
if (stationaryNode.nextConnection && !movingHasOutput) {
return stationaryNode.nextConnection;
let nextConnection: Blockly.RenderedConnection | null =
stationaryNode.nextConnection;
while (nextConnection) {
if (
movingBlock.workspace.connectionChecker.canConnect(
movingBlock.previousConnection,
nextConnection,
true,
Infinity,
)
) {
return nextConnection;
}
nextConnection =
nextConnection.getSourceBlock().getNextBlock()?.nextConnection ??
null;
}
}

// 3. Output connection. This will wrap around or displace.
Expand Down
29 changes: 29 additions & 0 deletions test/webdriverio/test/insert_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import * as chai from 'chai';
import * as Blockly from 'blockly';
import {Key} from 'webdriverio';
import {
getFocusedBlockType,
Expand Down Expand Up @@ -103,4 +104,32 @@ suite('Insert test', function () {
await getFocusedBlockType(this.browser),
);
});

test('Does not insert between immovable blocks', async function () {
// Focus the create canvas block; we want to ensure that the newly
// inserted block is not attached to its next connection, because doing
// so would splice it into an immovable stack.
await focusOnBlock(this.browser, 'create_canvas_1');
await this.browser.execute(() => {
Blockly.getMainWorkspace()
.getAllBlocks()
.forEach((b) => b.setMovable(false));
});
await tabNavigateToToolbox(this.browser);

// Insert 'if' block
await keyRight(this.browser);
// Choose.
await sendKeyAndWait(this.browser, Key.Enter);
// Confirm position.
await sendKeyAndWait(this.browser, Key.Enter);

// Assert inserted inside first block p5_setup not at top-level.
chai.assert.equal('controls_if', await getFocusedBlockType(this.browser));
await keyUp(this.browser);
chai.assert.equal(
'p5_background_color',
await getFocusedBlockType(this.browser),
);
});
});
Loading