1+ export default async function ( { feature, console } ) {
2+ await feature . page . waitForElement ( ".blocklyWorkspace" )
3+
4+ const ScratchBlocks = feature . traps . blocks ( ) ;
5+
6+ // Rerender the dragged block when updating the insertion marker
7+ const ogConnectMarker = ScratchBlocks . InsertionMarkerManager . prototype . connectMarker_ ;
8+ ScratchBlocks . InsertionMarkerManager . prototype . connectMarker_ = function ( ) {
9+ ogConnectMarker . call ( this ) ;
10+ if ( ! feature . self . disabled && this . firstMarker_ ) {
11+ const block = this ?. workspace_ ?. currentGesture_ ?. blockDragger_ ?. draggingBlock_ ;
12+ block . noMoveConnection = true ;
13+ if ( block ) block . render ( false ) ;
14+ }
15+ } ;
16+ const ogDisconnectMarker = ScratchBlocks . InsertionMarkerManager . prototype . disconnectMarker_ ;
17+ ScratchBlocks . InsertionMarkerManager . prototype . disconnectMarker_ = function ( ) {
18+ ogDisconnectMarker . call ( this ) ;
19+ if ( ! feature . self . disabled && this . firstMarker_ ) {
20+ const block = this ?. workspace_ ?. currentGesture_ ?. blockDragger_ ?. draggingBlock_ ;
21+ block . noMoveConnection = true ;
22+ if ( block ) block . render ( false ) ;
23+ }
24+ } ;
25+
26+ const ogDraw = ScratchBlocks . BlockSvg . prototype . renderDraw_ ;
27+ const ogMoveConnections = ScratchBlocks . BlockSvg . prototype . renderMoveConnections_ ;
28+ ScratchBlocks . BlockSvg . prototype . renderDraw_ = function ( iconWidth , inputRows ) {
29+ if ( feature . self . disabled ) return ogDraw . call ( this , iconWidth , inputRows ) ;
30+
31+ // If the block contains a statement (C) input and has an insertion marker,
32+ // use that to calculate the height of the statement inputs
33+ let computeBlock = this ;
34+ if ( this ?. workspace ?. currentGesture_ ?. blockDragger_ ?. draggedConnectionManager_ ) {
35+ const dragger = this . workspace . currentGesture_ . blockDragger_ ;
36+ const manager = dragger . draggedConnectionManager_ ;
37+ if (
38+ manager . markerConnection_ &&
39+ manager . firstMarker_ &&
40+ dragger . draggingBlock_ == this &&
41+ dragger . draggingBlock_ . type == manager . firstMarker_ . type
42+ ) {
43+ if ( inputRows . some ( ( row ) => row . some ( ( input ) => input . type === ScratchBlocks . NEXT_STATEMENT ) ) ) {
44+ computeBlock = manager . firstMarker_ ;
45+ }
46+ }
47+ }
48+
49+ // Change the height of substacks
50+ // (If we set inputRows to computeBlock.renderCompute_,
51+ // the references to the inputs would be wrong
52+ // so they just won't update properly)
53+ if ( computeBlock !== this ) {
54+ const _inputRows = computeBlock . renderCompute_ ( iconWidth ) ;
55+ for ( let i = 0 ; i < inputRows . length ; i ++ ) {
56+ const row = inputRows [ i ] ;
57+ let update = false ;
58+ for ( const input of row ) {
59+ if ( input . type === ScratchBlocks . NEXT_STATEMENT ) update = true ;
60+ }
61+ if ( update ) row . height = Math . max ( row . height , _inputRows [ i ] . height ) ;
62+ }
63+ }
64+
65+ ogDraw . call ( this , iconWidth , inputRows ) ;
66+
67+ // Moving the connections of a block while it's being dragged breaks it,
68+ // so don't
69+ if ( computeBlock === this && ! this . noMoveConnection ) ogMoveConnections . call ( this ) ;
70+ this . noMoveConnection = false ;
71+ } ;
72+ ScratchBlocks . BlockSvg . prototype . renderMoveConnections_ = function ( ) {
73+ if ( feature . self . disabled ) return ogMoveConnections . call ( this ) ;
74+ // Do nothing (this function is instead called by renderDraw_)
75+ } ;
76+ }
0 commit comments