Skip to content

Commit af57a3e

Browse files
authored
refactor: Make InsertionMarkerPreviewer's block serialization amenable to subclassing. (#9282)
1 parent 44e78b1 commit af57a3e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

core/insertion_marker_previewer.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,17 @@ export class InsertionMarkerPreviewer implements IConnectionPreviewer {
150150
return markerConn;
151151
}
152152

153-
private createInsertionMarker(origBlock: BlockSvg) {
154-
const blockJson = blocks.save(origBlock, {
153+
/**
154+
* Transforms the given block into a JSON representation used to construct an
155+
* insertion marker.
156+
*
157+
* @param block The block to serialize and use as an insertion marker.
158+
* @returns A JSON-formatted string corresponding to a serialized
159+
* representation of the given block suitable for use as an insertion
160+
* marker.
161+
*/
162+
protected serializeBlockToInsertionMarker(block: BlockSvg) {
163+
const blockJson = blocks.save(block, {
155164
addCoordinates: false,
156165
addInputBlocks: false,
157166
addNextBlocks: false,
@@ -160,10 +169,15 @@ export class InsertionMarkerPreviewer implements IConnectionPreviewer {
160169

161170
if (!blockJson) {
162171
throw new Error(
163-
`Failed to serialize source block. ${origBlock.toDevString()}`,
172+
`Failed to serialize source block. ${block.toDevString()}`,
164173
);
165174
}
166175

176+
return blockJson;
177+
}
178+
179+
private createInsertionMarker(origBlock: BlockSvg) {
180+
const blockJson = this.serializeBlockToInsertionMarker(origBlock);
167181
const result = blocks.append(blockJson, this.workspace) as BlockSvg;
168182

169183
// Turn shadow blocks that are created programmatically during

0 commit comments

Comments
 (0)