mirror of
https://github.com/google/blockly.git
synced 2026-06-11 13:45:14 +02:00
fix: don't allow disconnecting shadow blocks (#9964)
This commit is contained in:
@@ -940,10 +940,12 @@ export function registerDisconnectBlock() {
|
||||
const disconnectShortcut: ShortcutRegistry.KeyboardShortcut = {
|
||||
name: names.DISCONNECT,
|
||||
preconditionFn: (workspace, scope) => {
|
||||
const focused = scope.focusedNode;
|
||||
const result =
|
||||
!workspace.isDragging() &&
|
||||
!workspace.isReadOnly() &&
|
||||
scope.focusedNode instanceof BlockSvg;
|
||||
focused instanceof BlockSvg &&
|
||||
!focused.isShadow();
|
||||
|
||||
if (!result) {
|
||||
workspace.getAudioManager().playErrorBeep();
|
||||
|
||||
@@ -1036,6 +1036,23 @@ suite('Keyboard Shortcut Items', function () {
|
||||
assert.deepEqual(bounds, this.blockE.getBoundingRectangle());
|
||||
});
|
||||
|
||||
test('Does nothing for a shadow block', function () {
|
||||
this.blockH.setShadow(true);
|
||||
Blockly.getFocusManager().focusNode(this.blockH);
|
||||
assert.isTrue(this.blockH.outputConnection.isConnected());
|
||||
|
||||
this.injectionDiv.dispatchEvent(
|
||||
createKeyDownEvent(Blockly.utils.KeyCodes.X),
|
||||
);
|
||||
|
||||
// The shadow should remain connected to its parent input.
|
||||
assert.isTrue(this.blockH.outputConnection.isConnected());
|
||||
assert.strictEqual(
|
||||
Blockly.getFocusManager().getFocusedNode(),
|
||||
this.blockH,
|
||||
);
|
||||
});
|
||||
|
||||
test('Disconnects child blocks when triggered on top stack block', function () {
|
||||
Blockly.getFocusManager().focusNode(this.blockB);
|
||||
assert.isTrue(this.blockB.nextConnection.isConnected());
|
||||
|
||||
Reference in New Issue
Block a user