Skip to content

Commit b62471c

Browse files
authored
Add ctrl select support (#527)
* Add ctrl select support * fix the issue with clicking on overlapping objects * simplify the code, add meta to ctrl for macos * fix lock unlock with command on macos
1 parent 0a60bd9 commit b62471c

File tree

4 files changed

+286
-138
lines changed

4 files changed

+286
-138
lines changed

src/components/EditorCanvas/Area.jsx

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,47 @@ export default function Area({
4848
});
4949
};
5050

51-
const lockUnlockArea = () => {
52-
setBulkSelectedElements((prev) =>
53-
prev.filter((el) => el.id !== data.id || el.type !== ObjectType.AREA),
54-
);
55-
updateArea(data.id, { locked: !data.locked });
51+
const lockUnlockArea = (e) => {
52+
const locking = !data.locked;
53+
updateArea(data.id, { locked: locking });
54+
55+
const lockArea = () => {
56+
setSelectedElement({
57+
...selectedElement,
58+
element: ObjectType.NONE,
59+
id: -1,
60+
open: false,
61+
});
62+
setBulkSelectedElements((prev) =>
63+
prev.filter((el) => el.id !== data.id || el.type !== ObjectType.AREA),
64+
);
65+
};
66+
67+
const unlockArea = () => {
68+
const elementInBulk = {
69+
id: data.id,
70+
type: ObjectType.AREA,
71+
initialCoords: { x: data.x, y: data.y },
72+
currentCoords: { x: data.x, y: data.y },
73+
};
74+
if (e.ctrlKey || e.metaKey) {
75+
setBulkSelectedElements((prev) => [...prev, elementInBulk]);
76+
} else {
77+
setBulkSelectedElements([elementInBulk]);
78+
}
79+
setSelectedElement((prev) => ({
80+
...prev,
81+
element: ObjectType.AREA,
82+
id: data.id,
83+
open: false,
84+
}));
85+
};
86+
87+
if (locking) {
88+
lockArea();
89+
} else {
90+
unlockArea();
91+
}
5692
};
5793

5894
const edit = () => {

0 commit comments

Comments
 (0)