You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Fallback or error handling if the target cannot be resolved.
600
552
if(!target){
601
-
if(remoteTargetName){
602
-
// If a specific target name was provided but not found locally, it's a potential issue.
603
-
console.warn(`Collab RX: Target "${remoteTargetName}" for standard event type "${blocklyEvent.type}" (Block ID: ${blocklyEvent.blockId||'N/A'}) not found. VM update may be skipped or fail.`);
604
-
}else{
605
-
// If no remote target name was specified, it might be a truly global event.
606
-
// In such cases, attempt to use the currently editing target as a fallback.
if(constants.debugging&&target)console.log(`Collab RX: Standard event type "${blocklyEvent.type}" had no remoteTargetName. Using current editing target "${target.getName()}" for VM update attempt.`);
553
+
console.error(`Collab RX: Skipping event type "${eventJson.type}" due to inability to resolve target (Remote: "${remoteTargetName}").`);
console.warn(`Collab RX [move]: Block ${eventData.blockId} not found. Skipping move.`);
569
+
return;
609
570
}
571
+
if(constants.debugging)console.log(`Collab RX [move]: Applying custom move for block ${blockToMove.id}.`);
610
572
611
-
if(!target){
612
-
console.error(`Collab RX: Skipping standard event type "${blocklyEvent.type}" (Block ID: ${blocklyEvent.blockId||'N/A'}) due to inability to determine/resolve target (Remote: "${remoteTargetName}").`);
613
-
return;// Critical failure to resolve target, skip event.
573
+
// 1. Unplug the block first to ensure the old state is cleanly severed. This is the critical step.
574
+
if(blockToMove.getParent()){
575
+
if(constants.debugging)console.log(`Collab RX [move]: Unplugging block ${blockToMove.id} from parent.`);
576
+
blockToMove.unplug(false);
614
577
}
615
-
}
616
578
617
-
constcurrentEditingTargetName=helper.getCurrentEditingTargetName();// Get the name of the target currently being edited locally.
if(constants.debugging)console.log(`Collab RX: Skipping visual .run() for standard CREATE on block ${blocklyEvent.blockId} - block already exists in current workspace view.`);
668
681
canRunVisually=false;
669
682
}
670
-
// For other events (MOVE, CHANGE, DELETE), ensure the block exists before trying to apply changes visually.
if(constants.debugging)console.log(`Collab RX: Skipping visual .run() for ${blocklyEvent.type} on block ${blocklyEvent.blockId} - block not found in current workspace view.`);
@@ -677,9 +689,7 @@ export function processSpecificEvent(item) {
677
689
678
690
if(canRunVisually){
679
691
if(constants.debugging)console.log(`Collab RX: Applying standard event ${blocklyEvent.type} VISUALLY.`,item);
680
-
blocklyEvent.run(true);// Apply the event forward to the Blockly workspace.
681
-
// Refresh the toolbox if a procedure definition was created/modified or a block was deleted,
682
-
// as these can affect which blocks are available.
@@ -688,19 +698,16 @@ export function processSpecificEvent(item) {
688
698
}elseif(constants.debugging)console.log(`Collab RX: Skipping visual application of standard event ${blocklyEvent.type} because remote target "${remoteTargetName}" is not the current view "${currentEditingTargetName}".`);
689
699
690
700
// 2. Apply the event to the Scratch VM state.
691
-
// This ensures the underlying data model is consistent, regardless of what's visually shown.
if(constants.debugging)console.log(`Collab RX: Skipping VM .blocklyListen() for standard CREATE on block ${blocklyEvent.blockId} - block already exists in VM target "${target.getName()}".`);
698
705
canRunVmUpdate=false;
699
706
}
700
707
701
708
if(canRunVmUpdate){
702
709
if(constants.debugging)console.log(`Collab RX: Updating VM state for Target="${target.getName()}" via blocklyListen for event type ${blocklyEvent.type}.`);
703
-
target.blocks.blocklyListen(blocklyEvent);// Apply the event to the VM's block manager.
710
+
target.blocks.blocklyListen(blocklyEvent);
704
711
}
705
712
}else{
706
713
console.error(`Collab RX: Failed to update VM state for standard event type ${blocklyEvent?.type}. Target "${target?.getName()}" or its 'blocks.blocklyListen' method not found.`);
0 commit comments