Skip to content

Commit

Permalink
fix(core): fix select elements error after move node #WIK-15141 (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhuanwa authored Apr 17, 2024
1 parent 99fecff commit 43e1220
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-ears-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/core': patch
---

fix select elements error after move node
15 changes: 13 additions & 2 deletions packages/core/src/transforms/group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PlaitBoard, PlaitElement, PlaitGroupElement } from '../interfaces';
import { clearNodeWeakMap, createTestingBoard, fakeNodeWeakMap } from '../testing';
import { addSelectedElement } from '../utils';
import { addSelectedElement, getSelectedElements } from '../utils';
import { GroupTransforms } from './group';

const children: PlaitElement[] = [
Expand Down Expand Up @@ -96,7 +96,7 @@ const children: PlaitElement[] = [
groupId: 'JDQpa'
},
{
id: 'DPMaD',
id: 'DPMsD',
type: 'geometry',
shape: 'rectangle',
angle: 0,
Expand Down Expand Up @@ -161,4 +161,15 @@ describe('group transform', () => {
const elementIngroup = board.children.filter(item => item.groupId);
expect(elementIngroup.length).toBe(0);
});

it('should correctly moving elements when selecting elements from different layers for grouping.', () => {
addSelectedElement(board, [children[0], children[1], children[4], children[5]]);
GroupTransforms.addGroup(board);
expect(board.children[2].id).toBe(children[0].id);
expect(board.children[3].id).toBe(children[1].id);
expect(board.children[4].id).toBe(children[4].id);
expect(board.children[5].id).toBe(children[5].id);
const selectedElements = getSelectedElements(board);
expect(selectedElements.length).toBe(4);
});
});
5 changes: 3 additions & 2 deletions packages/core/src/utils/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createG, setAngleForG } from './dom';
import { drawRectangle } from './drawing/rectangle';
import { getRectangleByElements } from './element';
import { idCreator } from './id-creator';
import { getSelectedElements } from './selected-element';
import { cacheSelectedElements, getSelectedElements } from './selected-element';
import { isSelectionMoving } from './selection';
import { depthFirstRecursion } from './tree';
import { moveElementsToNewPath } from './common';
Expand Down Expand Up @@ -250,7 +250,8 @@ export const getEditingGroup = (board: PlaitBoard, element: PlaitElement) => {
return editingGroup;
};

export const moveElementsToNewPathAfterAddGroup = (board: PlaitBoard, moveElements: PlaitElement[], newPath: Path) => {
export const moveElementsToNewPathAfterAddGroup = (board: PlaitBoard, selectedElements: PlaitElement[], newPath: Path) => {
const moveElements = [...selectedElements];
sortElements(board, moveElements);
moveElements.pop();
moveElementsToNewPath(
Expand Down

0 comments on commit 43e1220

Please sign in to comment.