Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions pxtblocks/monkeyPatches/connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as Blockly from "blockly";

export function monkeyPatchConnection() {
const oldConnectionForOrphanedConnection = Blockly.Connection.getConnectionForOrphanedConnection;
Blockly.Connection.getConnectionForOrphanedConnection = function (startBlock: Blockly.Block, orphanConnection: Blockly.Connection) {
// When a block is dragged into an input that already has a non-shadow block connected, Blockly has
// some logic that checks to see if the block you just dragged has a single input and, if so, connects
// the previously connected block to the input of the block you just dragged. Presumably this is to make
// it easier to wrap blocks with a new block (for example, dragging an absolute value block onto a number
// in an equation will wrap it theoretically saving you an extra drag). However, nobody ever expects this
// behavior and only the most powerful of power users would use it to their advantage. It also can cause
// type errors when the displaced block is a variable since variables can be connected to any input regardless
// of what type they actually hold. It's better to just disable it entirely.
if (orphanConnection.type === Blockly.ConnectionType.OUTPUT_VALUE) {
return null;
}

return oldConnectionForOrphanedConnection(startBlock, orphanConnection);
}
}
2 changes: 2 additions & 0 deletions pxtblocks/monkeyPatches/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { monkeyPatchBlockSvg } from "./blockSvg";
import { monkeyPatchConnection } from "./connection";
import { monkeyPatchGesture } from "./gesture";
import { monkeyPatchGrid } from "./grid";
import { monkeyPatchAddKeyMapping } from "./shortcut_registry";
Expand All @@ -8,4 +9,5 @@ export function applyMonkeyPatches() {
monkeyPatchGrid();
monkeyPatchGesture();
monkeyPatchAddKeyMapping();
monkeyPatchConnection();
}
Loading