From 1d49ecb1a0e6e6774fc6580e2e15d83a83b7ea72 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 26 Jan 2024 14:33:27 -0800 Subject: [PATCH] fix: have the connection previewer use the registry (#7800) --- core/block_dragger.ts | 11 ++++++----- core/blockly.ts | 2 ++ .../insertion_marker_previewer.ts | 7 +++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/block_dragger.ts b/core/block_dragger.ts index 57c77bb0d..1cab37053 100644 --- a/core/block_dragger.ts +++ b/core/block_dragger.ts @@ -31,7 +31,6 @@ import {hasBubble} from './interfaces/i_has_bubble.js'; import * as deprecation from './utils/deprecation.js'; import * as layers from './layers.js'; import {ConnectionType, IConnectionPreviewer} from './blockly.js'; -import {InsertionMarkerPreviewer} from './connection_previewers/insertion_marker_previewer.js'; import {RenderedConnection} from './rendered_connection.js'; import {config} from './config.js'; import {ComponentManager} from './component_manager.js'; @@ -86,12 +85,14 @@ export class BlockDragger implements IBlockDragger { */ constructor(block: BlockSvg, workspace: WorkspaceSvg) { this.draggingBlock_ = block; - - // TODO: have this access the registry instead. - this.connectionPreviewer = new InsertionMarkerPreviewer(block); - this.workspace_ = workspace; + const previewerConstructor = registry.getClassFromOptions( + registry.Type.CONNECTION_PREVIEWER, + this.workspace_.options, + ); + this.connectionPreviewer = new previewerConstructor!(block); + /** * The location of the top left corner of the dragging block at the * beginning of the drag in workspace coordinates. diff --git a/core/blockly.ts b/core/blockly.ts index 9abea068e..92d4a6740 100644 --- a/core/blockly.ts +++ b/core/blockly.ts @@ -128,6 +128,7 @@ import {Input} from './inputs/input.js'; import {inputTypes} from './inputs/input_types.js'; import * as inputs from './inputs.js'; import {InsertionMarkerManager} from './insertion_marker_manager.js'; +import {InsertionMarkerPreviewer} from './connection_previewers/insertion_marker_previewer.js'; import {IASTNodeLocation} from './interfaces/i_ast_node_location.js'; import {IASTNodeLocationSvg} from './interfaces/i_ast_node_location_svg.js'; import {IASTNodeLocationWithBlock} from './interfaces/i_ast_node_location_with_block.js'; @@ -607,6 +608,7 @@ export {IMovable}; export {Input}; export {inputs}; export {InsertionMarkerManager}; +export {InsertionMarkerPreviewer}; export {IObservable, isObservable}; export {IPaster, isPaster}; export {IPositionable}; diff --git a/core/connection_previewers/insertion_marker_previewer.ts b/core/connection_previewers/insertion_marker_previewer.ts index 73f620dca..574fa8409 100644 --- a/core/connection_previewers/insertion_marker_previewer.ts +++ b/core/connection_previewers/insertion_marker_previewer.ts @@ -11,6 +11,7 @@ import {WorkspaceSvg} from '../workspace_svg.js'; import * as eventUtils from '../events/utils.js'; import * as constants from '../constants.js'; import * as renderManagement from '../render_management.js'; +import * as registry from '../registry.js'; /** * An error message to throw if the block created by createMarkerBlock_ is @@ -247,3 +248,9 @@ export class InsertionMarkerPreviewer implements IConnectionPreviewer { this.hidePreview(); } } + +registry.register( + registry.Type.CONNECTION_PREVIEWER, + registry.DEFAULT, + InsertionMarkerPreviewer, +);