Skip to content

Commit

Permalink
fix(common): do not handle the hierarchy of the group element when ad…
Browse files Browse the repository at this point in the history
…dGroup #WIK-15137 (#829)
  • Loading branch information
huanhuanwa authored Apr 16, 2024
1 parent 8459129 commit 99fecff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-waves-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/core': patch
---

do not handle the hierarchy of the group element when addGroup
9 changes: 4 additions & 5 deletions packages/core/src/transforms/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ export const addGroup = (board: PlaitBoard, elements?: PlaitElement[]) => {
NodeTransforms.setNode(board, { groupId: group.id }, path);
});
const selectedElements = getSelectedElements(board);
const highestIndexOfSelectedElement = getHighestIndexOfElement(board, [...selectedElements, ...selectedGroups]);
const highestIndexOfSelectedElement = getHighestIndexOfElement(board, selectedElements);
const indices = getElementsIndices(board, highestSelectedElements);
const isContinuous = isIndicesContinuous(indices);
if (!isContinuous) {
moveElementsToNewPathAfterAddGroup(board, [...selectedElements, ...selectedGroups], [highestIndexOfSelectedElement - 1]);
moveElementsToNewPathAfterAddGroup(board, selectedElements, [highestIndexOfSelectedElement - 1]);
}
const groupPath = [highestIndexOfSelectedElement + 1];
if (hasSelectedElementsInSameGroup(highestSelectedElements)) {
const newGroupId = selectedIsolatedElements[0].groupId;
NodeTransforms.insertNode(
Expand All @@ -41,10 +40,10 @@ export const addGroup = (board: PlaitBoard, elements?: PlaitElement[]) => {
...group,
groupId: newGroupId
},
groupPath
[board.children.length]
);
} else {
NodeTransforms.insertNode(board, group, groupPath);
NodeTransforms.insertNode(board, group, [board.children.length]);
}
}
};
Expand Down

0 comments on commit 99fecff

Please sign in to comment.