@@ -631,7 +631,7 @@ export default class StageStore implements IStageStore {
631
631
tree . unshift ( treeNode ) ;
632
632
this . _treeNodesMap . set ( id , treeNode ) ;
633
633
if ( isGroup ) {
634
- const subTreeNodes = this . _preserveGroupSubs ( node , [ ] ) ;
634
+ const subTreeNodes = this . _findGroupSubs ( node , [ ] ) ;
635
635
treeNode . children = subTreeNodes ;
636
636
}
637
637
}
@@ -675,7 +675,7 @@ export default class StageStore implements IStageStore {
675
675
result . push ( treeNode ) ;
676
676
this . _treeNodesMap . set ( prevId , treeNode ) ;
677
677
if ( prevIsGroup ) {
678
- this . _preserveGroupSubs ( prevNode , treeNode . children ) ;
678
+ this . _findGroupSubs ( prevNode , treeNode . children ) ;
679
679
}
680
680
findedSubs . add ( prevId ) ;
681
681
}
@@ -724,7 +724,7 @@ export default class StageStore implements IStageStore {
724
724
result . push ( treeNode ) ;
725
725
this . _treeNodesMap . set ( nextId , treeNode ) ;
726
726
if ( nextIsGroup ) {
727
- this . _preserveGroupSubs ( nextNode , treeNode . children ) ;
727
+ this . _findGroupSubs ( nextNode , treeNode . children ) ;
728
728
}
729
729
}
730
730
findedSubs . add ( nextId ) ;
@@ -744,7 +744,7 @@ export default class StageStore implements IStageStore {
744
744
* @param result
745
745
* @returns
746
746
*/
747
- private _preserveGroupSubs ( node : ILinkedNode < IElement > , result : ElementTreeNode [ ] ) : ElementTreeNode [ ] {
747
+ private _findGroupSubs ( node : ILinkedNode < IElement > , result : ElementTreeNode [ ] ) : ElementTreeNode [ ] {
748
748
const {
749
749
value : {
750
750
isGroup,
@@ -2865,15 +2865,20 @@ export default class StageStore implements IStageStore {
2865
2865
// 判断是否是组合内部子组件移动排序
2866
2866
if ( isGroupInternal ) {
2867
2867
const subIds = group . subIds ;
2868
- // 因为多个子组件在组合内部是不连续的,且tailNode可能是组合中最后一个子组件,所以,需要倒序查找第一个不在给定子组件集合中的子组件作为插入目标节点
2869
- for ( let i = subIds . length - 1 ; i >= 0 ; i -- ) {
2870
- const targetIndex = elementIds . findIndex ( id => id === subIds [ i ] ) ;
2871
- if ( targetIndex === - 1 ) {
2872
- const targetId = subIds [ i ] ;
2873
- targetNode = this . _elementsMap . get ( targetId ) ?. node ;
2874
- groupSubIds = LodashUtils . moveArrayElementsAfter ( subIds , elementIds , targetId ) ;
2875
- break ;
2868
+ const isTailInGroup = subIds [ subIds . length - 1 ] === tailNode . value . id ;
2869
+ if ( isTailInGroup ) {
2870
+ // 因为多个子组件在组合内部是不连续的,且tailNode可能是组合中最后一个子组件,所以,需要倒序查找第一个不在给定子组件集合中的子组件作为插入目标节点
2871
+ for ( let i = subIds . length - 1 ; i >= 0 ; i -- ) {
2872
+ const targetIndex = elementIds . findIndex ( id => id === subIds [ i ] ) ;
2873
+ if ( targetIndex === - 1 ) {
2874
+ const targetId = subIds [ i ] ;
2875
+ targetNode = this . _elementsMap . get ( targetId ) ?. node ;
2876
+ groupSubIds = LodashUtils . moveArrayElementsAfter ( subIds , elementIds , targetId ) ;
2877
+ break ;
2878
+ }
2876
2879
}
2880
+ } else {
2881
+ groupSubIds = LodashUtils . moveArrayElementsAfter ( subIds , elementIds , targetNode . value . id ) ;
2877
2882
}
2878
2883
// 如果要插入的目标节点是当前组合,表示数据出现异常,终止节点移动
2879
2884
if ( targetNode && targetNode . value === group ) {
0 commit comments