File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -218,15 +218,27 @@ export class Mover {
218218 /**
219219 * Get the source block for the cursor location, or undefined if no
220220 * source block can be found.
221+ * If the cursor is on a shadow block, walks up the tree until it finds
222+ * a non-shadow block to drag.
221223 *
222224 * @param workspace The workspace to inspect for a cursor.
223225 * @returns The source block, or undefined if no appropriate block
224226 * could be found.
225227 */
226228 protected getCurrentBlock ( workspace : WorkspaceSvg ) : BlockSvg | undefined {
227- const cursor = workspace ?. getCursor ( ) ;
228- const curNode = cursor ?. getCurNode ( ) ;
229- return ( curNode ?. getSourceBlock ( ) as BlockSvg ) ?? undefined ;
229+ const curNode = workspace ?. getCursor ( ) ?. getCurNode ( ) ;
230+ let block = curNode ?. getSourceBlock ( ) ;
231+ if ( ! block ) return undefined ;
232+ while ( block && block . isShadow ( ) ) {
233+ block = block . getParent ( ) ;
234+ if ( ! block ) {
235+ throw new Error (
236+ 'Tried to drag a shadow block with no parent. ' +
237+ 'Shadow blocks should always have parents.' ,
238+ ) ;
239+ }
240+ }
241+ return block as BlockSvg ;
230242 }
231243
232244 /**
You can’t perform that action at this time.
0 commit comments