Skip to content

Commit

Permalink
fix: have the connection previewer use the registry (#7800)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Feb 2, 2024
1 parent bdbfabc commit 1d49ecb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 6 additions & 5 deletions core/block_dragger.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions core/blockly.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -607,6 +608,7 @@ export {IMovable};
export {Input};
export {inputs};
export {InsertionMarkerManager};
export {InsertionMarkerPreviewer};
export {IObservable, isObservable};
export {IPaster, isPaster};
export {IPositionable};
Expand Down
7 changes: 7 additions & 0 deletions core/connection_previewers/insertion_marker_previewer.ts
Expand Up @@ -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
Expand Down Expand Up @@ -247,3 +248,9 @@ export class InsertionMarkerPreviewer implements IConnectionPreviewer {
this.hidePreview();
}
}

registry.register(
registry.Type.CONNECTION_PREVIEWER,
registry.DEFAULT,
InsertionMarkerPreviewer,
);

0 comments on commit 1d49ecb

Please sign in to comment.