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
4 changes: 4 additions & 0 deletions src/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,10 @@ const styles = `
stroke: revert-layer;
stroke-width: 1;
}

.blocklyInsertionMarker > g:not(:last-child) {
visibility: hidden;
}
`;

Blockly.Css.register(styles);
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import "./scratch_dragger";
import "./scratch_variable_map";
import "./scratch_variable_model";
import "./scratch_connection_checker";
import "./scratch_insertion_marker_previewer";
import "./flyout_checkbox_icon";
import "./events/events_block_comment_change";
import "./events/events_block_comment_collapse";
Expand Down
45 changes: 45 additions & 0 deletions src/scratch_insertion_marker_previewer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import * as Blockly from "blockly/core";

/**
* Displays an indicator of where a block being dragged will be connected.
*/
class ScratchInsertionMarkerPreviewer extends Blockly.InsertionMarkerPreviewer {
/**
* Transforms the given block into a JSON representation used to construct an
* insertion marker.
*
* @param block The block to serialize and use as an insertion marker.
* @returns A JSON-formatted string corresponding to a serialized
* representation of the given block suitable for use as an insertion
* marker.
*/
protected override serializeBlockToInsertionMarker(block: Blockly.BlockSvg) {
const blockJson = Blockly.serialization.blocks.save(block, {
addCoordinates: false,
addInputBlocks: true,
addNextBlocks: false,
doFullSerialization: false,
});

if (!blockJson) {
throw new Error(
`Failed to serialize source block. ${block.toDevString()}`
);
}

return blockJson;
}
}

Blockly.registry.register(
Blockly.registry.Type.CONNECTION_PREVIEWER,
Blockly.registry.DEFAULT,
ScratchInsertionMarkerPreviewer,
true
);