mirror of
https://github.com/google/blockly.git
synced 2026-01-06 16:40:07 +01:00
fix!(connection): Correctly handle multiple highlighted connections (#6416)
Modify RenderedConnection.prototype.highlight and .unhighlight to store the highlight path on this rather than as a static property on Connection (which is where it had been stored since this functionality was originally created, previously to RenderedConnection and Connection being split).
This commit is contained in:
committed by
GitHub
parent
e58cf77b7f
commit
5d3ba79ab3
@@ -53,6 +53,7 @@ export class RenderedConnection extends Connection {
|
||||
private readonly dbOpposite_: ConnectionDB;
|
||||
private readonly offsetInBlock_: Coordinate;
|
||||
private trackedState_: TrackedState;
|
||||
private highlightPath: SVGPathElement | null = null;
|
||||
|
||||
/** Connection this connection connects to. Null if not connected. */
|
||||
override targetConnection: RenderedConnection|null = null;
|
||||
@@ -302,26 +303,22 @@ export class RenderedConnection extends Connection {
|
||||
const xy = this.sourceBlock_.getRelativeToSurfaceXY();
|
||||
const x = this.x - xy.x;
|
||||
const y = this.y - xy.y;
|
||||
// AnyDuringMigration because: Property 'highlightedPath_' does not exist
|
||||
// on type 'typeof Connection'.
|
||||
(Connection as AnyDuringMigration).highlightedPath_ = dom.createSvgElement(
|
||||
Svg.PATH, {
|
||||
'class': 'blocklyHighlightedConnectionPath',
|
||||
'd': steps,
|
||||
'transform': 'translate(' + x + ',' + y + ')' +
|
||||
(this.sourceBlock_.RTL ? ' scale(-1 1)' : ''),
|
||||
},
|
||||
this.sourceBlock_.getSvgRoot());
|
||||
this.highlightPath = dom.createSvgElement(
|
||||
Svg.PATH, {
|
||||
'class': 'blocklyHighlightedConnectionPath',
|
||||
'd': steps,
|
||||
'transform': 'translate(' + x + ',' + y + ')' +
|
||||
(this.sourceBlock_.RTL ? ' scale(-1 1)' : ''),
|
||||
},
|
||||
this.sourceBlock_.getSvgRoot());
|
||||
}
|
||||
|
||||
/** Remove the highlighting around this connection. */
|
||||
unhighlight() {
|
||||
// AnyDuringMigration because: Property 'highlightedPath_' does not exist
|
||||
// on type 'typeof Connection'.
|
||||
dom.removeNode((Connection as AnyDuringMigration).highlightedPath_);
|
||||
// AnyDuringMigration because: Property 'highlightedPath_' does not exist
|
||||
// on type 'typeof Connection'.
|
||||
delete (Connection as AnyDuringMigration).highlightedPath_;
|
||||
if (this.highlightPath) {
|
||||
dom.removeNode(this.highlightPath);
|
||||
this.highlightPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user