Skip to content

Commit 9100947

Browse files
committed
Perf: optimized cursor movement
1 parent 84ccf68 commit 9100947

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/components/workspace/cursor.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,26 @@ export const Cursor = () => {
1313

1414
const Cursor = useSelector((state: any) => state.editor.cursor);
1515

16+
const workspace = document.getElementById(ids.workspace)?.getBoundingClientRect();
17+
const zoomControls = document.getElementById(ids.zoomControls)?.getBoundingClientRect();
18+
const mainControls = document.getElementById(ids.controls)?.getBoundingClientRect();
19+
1620
const move = (e) => {
1721
const ptr = pointer(e);
1822
const x = ptr[0];
1923
const y = ptr[1];
20-
const workspace = document.getElementById(ids.workspace)?.getBoundingClientRect();
21-
const zoomControls = document.getElementById(ids.zoomControls)?.getBoundingClientRect();
22-
const mainControls = document.getElementById(ids.controls)?.getBoundingClientRect();
23-
if (workspace) {
24-
const customCursor = document.getElementById(ids.cursor);
25-
if (
26-
isWithinBounds(x, y, workspace) &&
27-
!isWithinBounds(x, y, zoomControls) &&
28-
!isWithinBounds(x, y, mainControls) &&
29-
!resizeCursors.includes(e.target?.style?.cursor) &&
30-
!e.target.id.includes("radix:") &&
31-
e.target.getAttribute("role") !== "dialog"
32-
) {
33-
customCursor.style.display = "block";
34-
} else {
35-
customCursor.style.display = "none";
36-
}
24+
const customCursor = document.getElementById(ids.cursor);
25+
if (
26+
isWithinBounds(x, y, workspace) &&
27+
!isWithinBounds(x, y, zoomControls) &&
28+
!isWithinBounds(x, y, mainControls) &&
29+
!resizeCursors.includes(e.target?.style?.cursor) &&
30+
!e.target.id.includes("radix:") &&
31+
e.target.getAttribute("role") !== "dialog"
32+
) {
33+
customCursor.classList.remove("hidden");
34+
} else {
35+
customCursor.classList.add("hidden");
3736
}
3837
setCursorX(x);
3938
setCursorY(y);

0 commit comments

Comments
 (0)