@@ -55,12 +55,6 @@ export class Mover {
55
55
*/
56
56
private oldDragStrategy : IDragStrategy | null = null ;
57
57
58
- /**
59
- * The current block being moved, which is set at the start of a move and
60
- * reset at the end of a move.
61
- */
62
- private currentBlock : BlockSvg | null = null ;
63
-
64
58
constructor ( protected navigation : Navigation ) { }
65
59
66
60
/**
@@ -107,7 +101,6 @@ export class Mover {
107
101
const cursor = workspace ?. getCursor ( ) ;
108
102
const block = this . getCurrentBlock ( workspace ) ;
109
103
if ( ! cursor || ! block ) throw new Error ( 'precondition failure' ) ;
110
- this . currentBlock = block ;
111
104
112
105
// Select and focus block.
113
106
common . setSelected ( block ) ;
@@ -148,13 +141,11 @@ export class Mover {
148
141
new utils . Coordinate ( 0 , 0 ) ,
149
142
) ;
150
143
151
- // Scroll into view after block has finished moving.
152
- setTimeout ( ( ) => this . scrollCurrentBlockIntoView ( workspace ) , 0 ) ;
153
-
154
144
this . unpatchWorkspace ( workspace ) ;
155
145
this . unpatchDragStrategy ( info . block ) ;
156
146
this . moves . delete ( workspace ) ;
157
- this . currentBlock = null ;
147
+ // Delay scroll until after block has finished moving.
148
+ setTimeout ( ( ) => this . scrollCurrentBlockIntoView ( workspace ) , 0 ) ;
158
149
return true ;
159
150
}
160
151
@@ -183,13 +174,11 @@ export class Mover {
183
174
new utils . Coordinate ( 0 , 0 ) ,
184
175
) ;
185
176
186
- // Scroll into view after block has finished moving.
187
- setTimeout ( ( ) => this . scrollCurrentBlockIntoView ( workspace ) , 0 ) ;
188
-
189
177
this . unpatchWorkspace ( workspace ) ;
190
178
this . unpatchDragStrategy ( info . block ) ;
191
179
this . moves . delete ( workspace ) ;
192
- this . currentBlock = null ;
180
+ // Delay scroll until after block has finished moving.
181
+ setTimeout ( ( ) => this . scrollCurrentBlockIntoView ( workspace ) , 0 ) ;
193
182
return true ;
194
183
}
195
184
@@ -328,14 +317,15 @@ export class Mover {
328
317
/**
329
318
* Scrolls the current block into view if one exists.
330
319
*
331
- * @param workspace The workspace to scroll the given bounds into view in .
320
+ * @param workspace The workspace to get current block from .
332
321
* @param padding Amount of spacing to put between the bounds and the edge of
333
322
* the workspace's viewport.
334
323
*/
335
324
private scrollCurrentBlockIntoView ( workspace : WorkspaceSvg , padding = 10 ) {
336
- if ( this . currentBlock ) {
325
+ const blockToView = this . getCurrentBlock ( workspace ) ;
326
+ if ( blockToView ) {
337
327
workspace . scrollBoundsIntoView (
338
- this . currentBlock . getBoundingRectangleWithoutChildren ( ) ,
328
+ blockToView . getBoundingRectangleWithoutChildren ( ) ,
339
329
padding ,
340
330
) ;
341
331
}
0 commit comments