Skip to content

Commit 833b227

Browse files
committed
Add ctrl select support
1 parent 0e196de commit 833b227

File tree

5 files changed

+311
-138
lines changed

5 files changed

+311
-138
lines changed

src/components/EditorCanvas/Area.jsx

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ import {
1919
import { useTranslation } from "react-i18next";
2020
import { useHover } from "usehooks-ts";
2121

22-
export default function Area({
23-
data,
24-
onPointerDown,
25-
setResize,
26-
setInitDimensions,
27-
}) {
22+
export default function Area({ data, setResize, setInitDimensions }) {
2823
const ref = useRef(null);
2924
const isHovered = useHover(ref);
3025
const { layout } = useLayout();
@@ -48,11 +43,47 @@ export default function Area({
4843
});
4944
};
5045

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 });
46+
const lockUnlockArea = (e) => {
47+
const locking = !data.locked;
48+
updateArea(data.id, { locked: locking });
49+
50+
const lockArea = () => {
51+
setSelectedElement({
52+
...selectedElement,
53+
element: ObjectType.NONE,
54+
id: -1,
55+
open: false,
56+
});
57+
setBulkSelectedElements((prev) =>
58+
prev.filter((el) => el.id !== data.id || el.type !== ObjectType.AREA),
59+
);
60+
};
61+
62+
const unlockArea = () => {
63+
if (e.ctrlKey) {
64+
setBulkSelectedElements((prev) => [
65+
...prev,
66+
{
67+
id: data.id,
68+
type: ObjectType.AREA,
69+
initialCoords: { x: data.x, y: data.y },
70+
currentCoords: { x: data.x, y: data.y },
71+
},
72+
]);
73+
}
74+
setSelectedElement((prev) => ({
75+
...prev,
76+
element: ObjectType.AREA,
77+
id: data.id,
78+
open: false,
79+
}));
80+
};
81+
82+
if (locking) {
83+
lockArea();
84+
} else {
85+
unlockArea();
86+
}
5687
};
5788

5889
const edit = () => {
@@ -116,7 +147,6 @@ export default function Area({
116147
y={data.y}
117148
width={data.width > 0 ? data.width : 0}
118149
height={data.height > 0 ? data.height : 0}
119-
onPointerDown={onPointerDown}
120150
>
121151
<div
122152
className={`w-full h-full p-2 rounded cursor-move border-2 ${

0 commit comments

Comments
 (0)