Skip to content

Commit 0e22a79

Browse files
authored
release: v10.4.3
Merge pull request #7917 from BeksOmega/rc/v10.4.3
2 parents bdc416f + 6a29acb commit 0e22a79

File tree

3 files changed

+59
-36
lines changed

3 files changed

+59
-36
lines changed

core/connection_previewers/insertion_marker_previewer.ts

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import * as eventUtils from '../events/utils.js';
1212
import * as constants from '../constants.js';
1313
import * as renderManagement from '../render_management.js';
1414
import * as registry from '../registry.js';
15+
import {Renderer as ZelosRenderer} from '../renderers/zelos/renderer.js';
16+
import {ConnectionType} from '../connection_type.js';
1517

1618
/**
1719
* An error message to throw if the block created by createMarkerBlock_ is
@@ -86,52 +88,73 @@ export class InsertionMarkerPreviewer implements IConnectionPreviewer {
8688
eventUtils.disable();
8789
try {
8890
this.hidePreview();
89-
const dragged = draggedConn.getSourceBlock();
90-
const marker = this.createInsertionMarker(dragged);
91-
const markerConn = this.getMatchingConnection(
92-
dragged,
93-
marker,
94-
draggedConn,
95-
);
96-
if (!markerConn) {
97-
throw Error('Could not create insertion marker to preview connection');
98-
}
99-
100-
// Render disconnected from everything else so that we have a valid
101-
// connection location.
102-
marker.queueRender();
103-
renderManagement.triggerQueuedRenders();
10491

105-
// Connect() also renders the insertion marker.
106-
markerConn.connect(staticConn);
107-
108-
const originalOffsetToTarget = {
109-
x: staticConn.x - markerConn.x,
110-
y: staticConn.y - markerConn.y,
111-
};
112-
const originalOffsetInBlock = markerConn.getOffsetInBlock().clone();
113-
renderManagement.finishQueuedRenders().then(() => {
114-
// Position so that the existing block doesn't move.
115-
marker?.positionNearConnection(
116-
markerConn,
117-
originalOffsetToTarget,
118-
originalOffsetInBlock,
119-
);
120-
marker?.getSvgRoot().setAttribute('visibility', 'visible');
121-
});
92+
// TODO(7898): Instead of special casing, we should change the dragger to
93+
// track the change in distance between the dragged connection and the
94+
// static connection, so that it doesn't disconnect unless that
95+
// (+ a bit) has been exceeded.
96+
if (this.shouldUseMarkerPreview(draggedConn, staticConn)) {
97+
this.markerConn = this.previewMarker(draggedConn, staticConn);
98+
}
12299

123100
if (this.workspace.getRenderer().shouldHighlightConnection(staticConn)) {
124101
staticConn.highlight();
125102
}
126103

127-
this.markerConn = markerConn;
128104
this.draggedConn = draggedConn;
129105
this.staticConn = staticConn;
130106
} finally {
131107
eventUtils.enable();
132108
}
133109
}
134110

111+
private shouldUseMarkerPreview(
112+
_draggedConn: RenderedConnection,
113+
staticConn: RenderedConnection,
114+
): boolean {
115+
return (
116+
staticConn.type === ConnectionType.PREVIOUS_STATEMENT ||
117+
staticConn.type === ConnectionType.NEXT_STATEMENT ||
118+
!(this.workspace.getRenderer() instanceof ZelosRenderer)
119+
);
120+
}
121+
122+
private previewMarker(
123+
draggedConn: RenderedConnection,
124+
staticConn: RenderedConnection,
125+
): RenderedConnection {
126+
const dragged = draggedConn.getSourceBlock();
127+
const marker = this.createInsertionMarker(dragged);
128+
const markerConn = this.getMatchingConnection(dragged, marker, draggedConn);
129+
if (!markerConn) {
130+
throw Error('Could not create insertion marker to preview connection');
131+
}
132+
133+
// Render disconnected from everything else so that we have a valid
134+
// connection location.
135+
marker.queueRender();
136+
renderManagement.triggerQueuedRenders();
137+
138+
// Connect() also renders the insertion marker.
139+
markerConn.connect(staticConn);
140+
141+
const originalOffsetToTarget = {
142+
x: staticConn.x - markerConn.x,
143+
y: staticConn.y - markerConn.y,
144+
};
145+
const originalOffsetInBlock = markerConn.getOffsetInBlock().clone();
146+
renderManagement.finishQueuedRenders().then(() => {
147+
// Position so that the existing block doesn't move.
148+
marker?.positionNearConnection(
149+
markerConn,
150+
originalOffsetToTarget,
151+
originalOffsetInBlock,
152+
);
153+
marker?.getSvgRoot().setAttribute('visibility', 'visible');
154+
});
155+
return markerConn;
156+
}
157+
135158
private createInsertionMarker(origBlock: BlockSvg) {
136159
const result = this.workspace.newBlock(origBlock.type);
137160
result.setInsertionMarker(true);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blockly",
3-
"version": "10.4.2",
3+
"version": "10.4.3",
44
"description": "Blockly is a library for building visual programming editors.",
55
"keywords": [
66
"blockly"

0 commit comments

Comments
 (0)