Skip to content

Commit 5e131d9

Browse files
authored
fix(mover): Don't heal rows when disconnecting at start of move (#537)
* test(mover): Add mover test blocks and (empty) suite * test(mover): Add tests for starting moves of statement and value blocks * test(mover): Improve error handling in getSelectedNeighbourInfo * refactor(tests): Factor out getConnectedBlockInfo; improve naming Create a new test helper to get info about what's connected to a given connection, used in both move tests, plus rename getSelectedNeighbourInfo to getFocusedNeighbourInfo. * fix(mover): Don't heal rows when disconnecting at start of move Modify KeyboardDragStrategy.prototype.shouldHealStack so that only stacks will be healed. * fix(tests): Fix lint * fix(tests): Don't .only away all the other tests * chore: Format
1 parent 2fd7671 commit 5e131d9

File tree

5 files changed

+520
-1
lines changed

5 files changed

+520
-1
lines changed

src/keyboard_drag_strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,6 @@ export class KeyboardDragStrategy extends dragging.BlockDragStrategy {
326326
}
327327

328328
override shouldHealStack(e: PointerEvent | undefined): boolean {
329-
return true;
329+
return Boolean(this.block.previousConnection);
330330
}
331331
}

test/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
<option value="navigationTestBlocks">
185185
navigation test blocks
186186
</option>
187+
<option value="moveTestBlocks">move test blocks</option>
187188
</select>
188189
</div>
189190
<div>

test/loadTestBlocks.js

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,298 @@ const navigationTestBlocks = {
570570
},
571571
};
572572

573+
const moveTestBlocks = {
574+
'blocks': {
575+
'languageVersion': 0,
576+
'blocks': [
577+
{
578+
'type': 'p5_setup',
579+
'id': 'p5_setup_1',
580+
'x': 0,
581+
'y': 75,
582+
'deletable': false,
583+
'inputs': {
584+
'STATEMENTS': {
585+
'block': {
586+
'type': 'p5_canvas',
587+
'id': 'p5_canvas_1',
588+
'deletable': false,
589+
'movable': false,
590+
'fields': {
591+
'WIDTH': 400,
592+
'HEIGHT': 400,
593+
},
594+
},
595+
},
596+
},
597+
},
598+
{
599+
'type': 'p5_draw',
600+
'id': 'p5_draw_1',
601+
'x': 0,
602+
'y': 332,
603+
'deletable': false,
604+
'inputs': {
605+
'STATEMENTS': {
606+
'block': {
607+
'type': 'controls_if',
608+
'id': 'statement_1',
609+
'inputs': {
610+
'IF0': {
611+
'block': {
612+
'type': 'logic_operation',
613+
'id': 'value_1',
614+
'fields': {
615+
'OP': 'AND',
616+
},
617+
'inputs': {
618+
'A': {
619+
'block': {
620+
'type': 'logic_boolean',
621+
'id': 'value_1_1',
622+
'fields': {
623+
'BOOL': 'TRUE',
624+
},
625+
},
626+
},
627+
'B': {
628+
'block': {
629+
'type': 'logic_boolean',
630+
'id': 'value_1_2',
631+
'fields': {
632+
'BOOL': 'TRUE',
633+
},
634+
},
635+
},
636+
},
637+
},
638+
},
639+
},
640+
'next': {
641+
'block': {
642+
'type': 'controls_if',
643+
'id': 'statement_2',
644+
'inputs': {
645+
'IF0': {
646+
'block': {
647+
'type': 'logic_negate',
648+
'id': 'value_2',
649+
'inputs': {
650+
'BOOL': {
651+
'block': {
652+
'type': 'logic_boolean',
653+
'id': 'value_2_1',
654+
'fields': {
655+
'BOOL': 'TRUE',
656+
},
657+
},
658+
},
659+
},
660+
},
661+
},
662+
},
663+
'next': {
664+
'block': {
665+
'type': 'controls_repeat_ext',
666+
'id': 'statement_3',
667+
'inputs': {
668+
'TIMES': {
669+
'shadow': {
670+
'type': 'math_number',
671+
'id': 'shadow_3',
672+
'fields': {
673+
'NUM': 10,
674+
},
675+
},
676+
'block': {
677+
'type': 'math_arithmetic',
678+
'id': 'value_3',
679+
'fields': {
680+
'OP': 'ADD',
681+
},
682+
'inputs': {
683+
'A': {
684+
'shadow': {
685+
'type': 'math_number',
686+
'id': 'shadow_3_1',
687+
'fields': {
688+
'NUM': 1,
689+
},
690+
},
691+
'block': {
692+
'type': 'math_number',
693+
'id': 'value_3_1',
694+
'fields': {
695+
'NUM': 0,
696+
},
697+
},
698+
},
699+
'B': {
700+
'shadow': {
701+
'type': 'math_number',
702+
'id': 'shadow_3_2',
703+
'fields': {
704+
'NUM': 1,
705+
},
706+
},
707+
'block': {
708+
'type': 'math_number',
709+
'id': 'value_3_2',
710+
'fields': {
711+
'NUM': 0,
712+
},
713+
},
714+
},
715+
},
716+
},
717+
},
718+
},
719+
'next': {
720+
'block': {
721+
'type': 'controls_repeat_ext',
722+
'id': 'statement_4',
723+
'inputs': {
724+
'TIMES': {
725+
'shadow': {
726+
'type': 'math_number',
727+
'id': 'shadow_4',
728+
'fields': {
729+
'NUM': 10,
730+
},
731+
},
732+
'block': {
733+
'type': 'math_trig',
734+
'id': 'value_4',
735+
'fields': {
736+
'OP': 'SIN',
737+
},
738+
'inputs': {
739+
'NUM': {
740+
'shadow': {
741+
'type': 'math_number',
742+
'id': 'shadow_4_1',
743+
'fields': {
744+
'NUM': 45,
745+
},
746+
},
747+
'block': {
748+
'type': 'math_number',
749+
'id': 'value_4_1',
750+
'fields': {
751+
'NUM': 180,
752+
},
753+
},
754+
},
755+
},
756+
},
757+
},
758+
},
759+
'next': {
760+
'block': {
761+
'type': 'text_print',
762+
'id': 'statement_5',
763+
'inputs': {
764+
'TEXT': {
765+
'shadow': {
766+
'type': 'text',
767+
'id': 'shadow_5',
768+
'fields': {
769+
'TEXT': 'abc',
770+
},
771+
},
772+
'block': {
773+
'type': 'text_join',
774+
'id': 'value_5',
775+
'extraState': {
776+
'itemCount': 2,
777+
},
778+
'inputs': {
779+
'ADD0': {
780+
'block': {
781+
'type': 'text',
782+
'id': 'value_5_1',
783+
'fields': {
784+
'TEXT': 'test',
785+
},
786+
},
787+
},
788+
'ADD1': {
789+
'block': {
790+
'type': 'text',
791+
'id': 'value_5_2',
792+
'fields': {
793+
'TEXT': 'test',
794+
},
795+
},
796+
},
797+
},
798+
},
799+
},
800+
},
801+
'next': {
802+
'block': {
803+
'type': 'text_print',
804+
'id': 'statement_6',
805+
'inputs': {
806+
'TEXT': {
807+
'shadow': {
808+
'type': 'text',
809+
'id': 'shadow_6',
810+
'fields': {
811+
'TEXT': 'abc',
812+
},
813+
},
814+
'block': {
815+
'type': 'text_reverse',
816+
'id': 'value_6',
817+
'inputs': {
818+
'TEXT': {
819+
'shadow': {
820+
'type': 'text',
821+
'id': 'shadow_6_1',
822+
'fields': {
823+
'TEXT': '',
824+
},
825+
},
826+
'block': {
827+
'type': 'text',
828+
'id': 'value_6_1',
829+
'fields': {
830+
'TEXT': 'test',
831+
},
832+
},
833+
},
834+
},
835+
},
836+
},
837+
},
838+
'next': {
839+
'block': {
840+
'type': 'draw_emoji',
841+
'id': 'statement_7',
842+
'fields': {
843+
'emoji': '❤️',
844+
},
845+
},
846+
},
847+
},
848+
},
849+
},
850+
},
851+
},
852+
},
853+
},
854+
},
855+
},
856+
},
857+
},
858+
},
859+
},
860+
},
861+
],
862+
},
863+
};
864+
573865
/**
574866
* Loads saved state from local storage into the given workspace.
575867
* @param {Blockly.Workspace} workspace Blockly workspace to load into.
@@ -582,6 +874,7 @@ export const load = function (workspace, scenarioString) {
582874
'simpleCircle': simpleCircle,
583875
'moreBlocks': moreBlocks,
584876
'navigationTestBlocks': navigationTestBlocks,
877+
'moveTestBlocks': moveTestBlocks,
585878
};
586879

587880
const data = JSON.stringify(scenarioMap[scenarioString]);

0 commit comments

Comments
 (0)