@@ -412,6 +412,24 @@ const LISTS_GETINDEX = {
412412 this . appendDummyInput ( )
413413 . appendField ( modeMenu , 'MODE' )
414414 . appendField ( '' , 'SPACE' ) ;
415+ const menu = fieldRegistry . fromJson ( {
416+ type : 'field_dropdown' ,
417+ options : this . WHERE_OPTIONS ,
418+ } ) as FieldDropdown ;
419+ menu . setValidator (
420+ /** @param value The input value. */
421+ function ( this : FieldDropdown , value : string ) {
422+ const oldValue : string | null = this . getValue ( ) ;
423+ const oldAt = oldValue === 'FROM_START' || oldValue === 'FROM_END' ;
424+ const newAt = value === 'FROM_START' || value === 'FROM_END' ;
425+ if ( newAt !== oldAt ) {
426+ const block = this . getSourceBlock ( ) as GetIndexBlock ;
427+ block . updateAt_ ( newAt ) ;
428+ }
429+ return undefined ;
430+ } ,
431+ ) ;
432+ this . appendDummyInput ( ) . appendField ( menu , 'WHERE' ) ;
415433 this . appendDummyInput ( 'AT' ) ;
416434 if ( Msg [ 'LISTS_GET_INDEX_TAIL' ] ) {
417435 this . appendDummyInput ( 'TAIL' ) . appendField ( Msg [ 'LISTS_GET_INDEX_TAIL' ] ) ;
@@ -577,31 +595,6 @@ const LISTS_GETINDEX = {
577595 } else {
578596 this . appendDummyInput ( 'AT' ) ;
579597 }
580- const menu = fieldRegistry . fromJson ( {
581- type : 'field_dropdown' ,
582- options : this . WHERE_OPTIONS ,
583- } ) as FieldDropdown ;
584- menu . setValidator (
585- /**
586- * @param value The input value.
587- * @returns Null if the field has been replaced; otherwise undefined.
588- */
589- function ( this : FieldDropdown , value : string ) {
590- const newAt = value === 'FROM_START' || value === 'FROM_END' ;
591- // The 'isAt' variable is available due to this function being a
592- // closure.
593- if ( newAt !== isAt ) {
594- const block = this . getSourceBlock ( ) as GetIndexBlock ;
595- block . updateAt_ ( newAt ) ;
596- // This menu has been destroyed and replaced. Update the
597- // replacement.
598- block . setFieldValue ( value , 'WHERE' ) ;
599- return null ;
600- }
601- return undefined ;
602- } ,
603- ) ;
604- this . getInput ( 'AT' ) ! . appendField ( menu , 'WHERE' ) ;
605598 if ( Msg [ 'LISTS_GET_INDEX_TAIL' ] ) {
606599 this . moveInputBefore ( 'TAIL' , null ) ;
607600 }
@@ -644,6 +637,24 @@ const LISTS_SETINDEX = {
644637 this . appendDummyInput ( )
645638 . appendField ( operationDropdown , 'MODE' )
646639 . appendField ( '' , 'SPACE' ) ;
640+ const menu = fieldRegistry . fromJson ( {
641+ type : 'field_dropdown' ,
642+ options : this . WHERE_OPTIONS ,
643+ } ) as FieldDropdown ;
644+ menu . setValidator (
645+ /** @param value The input value. */
646+ function ( this : FieldDropdown , value : string ) {
647+ const oldValue : string | null = this . getValue ( ) ;
648+ const oldAt = oldValue === 'FROM_START' || oldValue === 'FROM_END' ;
649+ const newAt = value === 'FROM_START' || value === 'FROM_END' ;
650+ if ( newAt !== oldAt ) {
651+ const block = this . getSourceBlock ( ) as SetIndexBlock ;
652+ block . updateAt_ ( newAt ) ;
653+ }
654+ return undefined ;
655+ } ,
656+ ) ;
657+ this . appendDummyInput ( ) . appendField ( menu , 'WHERE' ) ;
647658 this . appendDummyInput ( 'AT' ) ;
648659 this . appendValueInput ( 'TO' ) . appendField ( Msg [ 'LISTS_SET_INDEX_INPUT_TO' ] ) ;
649660 this . setInputsInline ( true ) ;
@@ -756,36 +767,10 @@ const LISTS_SETINDEX = {
756767 } else {
757768 this . appendDummyInput ( 'AT' ) ;
758769 }
759- const menu = fieldRegistry . fromJson ( {
760- type : 'field_dropdown' ,
761- options : this . WHERE_OPTIONS ,
762- } ) as FieldDropdown ;
763- menu . setValidator (
764- /**
765- * @param value The input value.
766- * @returns Null if the field has been replaced; otherwise undefined.
767- */
768- function ( this : FieldDropdown , value : string ) {
769- const newAt = value === 'FROM_START' || value === 'FROM_END' ;
770- // The 'isAt' variable is available due to this function being a
771- // closure.
772- if ( newAt !== isAt ) {
773- const block = this . getSourceBlock ( ) as SetIndexBlock ;
774- block . updateAt_ ( newAt ) ;
775- // This menu has been destroyed and replaced. Update the
776- // replacement.
777- block . setFieldValue ( value , 'WHERE' ) ;
778- return null ;
779- }
780- return undefined ;
781- } ,
782- ) ;
783770 this . moveInputBefore ( 'AT' , 'TO' ) ;
784771 if ( this . getInput ( 'ORDINAL' ) ) {
785772 this . moveInputBefore ( 'ORDINAL' , 'TO' ) ;
786773 }
787-
788- this . getInput ( 'AT' ) ! . appendField ( menu , 'WHERE' ) ;
789774 } ,
790775} ;
791776blocks [ 'lists_setIndex' ] = LISTS_SETINDEX ;
@@ -818,7 +803,30 @@ const LISTS_GETSUBLIST = {
818803 this . appendValueInput ( 'LIST' )
819804 . setCheck ( 'Array' )
820805 . appendField ( Msg [ 'LISTS_GET_SUBLIST_INPUT_IN_LIST' ] ) ;
806+ const createMenu = ( n : 1 | 2 ) : FieldDropdown => {
807+ const menu = fieldRegistry . fromJson ( {
808+ type : 'field_dropdown' ,
809+ options :
810+ this [ ( 'WHERE_OPTIONS_' + n ) as 'WHERE_OPTIONS_1' | 'WHERE_OPTIONS_2' ] ,
811+ } ) as FieldDropdown ;
812+ menu . setValidator (
813+ /** @param value The input value. */
814+ function ( this : FieldDropdown , value : string ) {
815+ const oldValue : string | null = this . getValue ( ) ;
816+ const oldAt = oldValue === 'FROM_START' || oldValue === 'FROM_END' ;
817+ const newAt = value === 'FROM_START' || value === 'FROM_END' ;
818+ if ( newAt !== oldAt ) {
819+ const block = this . getSourceBlock ( ) as GetSublistBlock ;
820+ block . updateAt_ ( n , newAt ) ;
821+ }
822+ return undefined ;
823+ } ,
824+ ) ;
825+ return menu ;
826+ } ;
827+ this . appendDummyInput ( 'WHERE1_INPUT' ) . appendField ( createMenu ( 1 ) , 'WHERE1' ) ;
821828 this . appendDummyInput ( 'AT1' ) ;
829+ this . appendDummyInput ( 'WHERE2_INPUT' ) . appendField ( createMenu ( 2 ) , 'WHERE2' ) ;
822830 this . appendDummyInput ( 'AT2' ) ;
823831 if ( Msg [ 'LISTS_GET_SUBLIST_TAIL' ] ) {
824832 this . appendDummyInput ( 'TAIL' ) . appendField ( Msg [ 'LISTS_GET_SUBLIST_TAIL' ] ) ;
@@ -896,35 +904,10 @@ const LISTS_GETSUBLIST = {
896904 } else {
897905 this . appendDummyInput ( 'AT' + n ) ;
898906 }
899- const menu = fieldRegistry . fromJson ( {
900- type : 'field_dropdown' ,
901- options :
902- this [ ( 'WHERE_OPTIONS_' + n ) as 'WHERE_OPTIONS_1' | 'WHERE_OPTIONS_2' ] ,
903- } ) as FieldDropdown ;
904- menu . setValidator (
905- /**
906- * @param value The input value.
907- * @returns Null if the field has been replaced; otherwise undefined.
908- */
909- function ( this : FieldDropdown , value : string ) {
910- const newAt = value === 'FROM_START' || value === 'FROM_END' ;
911- // The 'isAt' variable is available due to this function being a
912- // closure.
913- if ( newAt !== isAt ) {
914- const block = this . getSourceBlock ( ) as GetSublistBlock ;
915- block . updateAt_ ( n , newAt ) ;
916- // This menu has been destroyed and replaced.
917- // Update the replacement.
918- block . setFieldValue ( value , 'WHERE' + n ) ;
919- return null ;
920- }
921- } ,
922- ) ;
923- this . getInput ( 'AT' + n ) ! . appendField ( menu , 'WHERE' + n ) ;
924907 if ( n === 1 ) {
925- this . moveInputBefore ( 'AT1' , 'AT2 ' ) ;
908+ this . moveInputBefore ( 'AT1' , 'WHERE2_INPUT ' ) ;
926909 if ( this . getInput ( 'ORDINAL1' ) ) {
927- this . moveInputBefore ( 'ORDINAL1' , 'AT2 ' ) ;
910+ this . moveInputBefore ( 'ORDINAL1' , 'WHERE2_INPUT ' ) ;
928911 }
929912 }
930913 if ( Msg [ 'LISTS_GET_SUBLIST_TAIL' ] ) {
0 commit comments