Skip to content

Commit

Permalink
Perf: optimized cursor movement
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Nov 24, 2024
1 parent 84ccf68 commit 9100947
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/components/workspace/cursor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,26 @@ export const Cursor = () => {

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

const workspace = document.getElementById(ids.workspace)?.getBoundingClientRect();
const zoomControls = document.getElementById(ids.zoomControls)?.getBoundingClientRect();
const mainControls = document.getElementById(ids.controls)?.getBoundingClientRect();

const move = (e) => {
const ptr = pointer(e);
const x = ptr[0];
const y = ptr[1];
const workspace = document.getElementById(ids.workspace)?.getBoundingClientRect();
const zoomControls = document.getElementById(ids.zoomControls)?.getBoundingClientRect();
const mainControls = document.getElementById(ids.controls)?.getBoundingClientRect();
if (workspace) {
const customCursor = document.getElementById(ids.cursor);
if (
isWithinBounds(x, y, workspace) &&
!isWithinBounds(x, y, zoomControls) &&
!isWithinBounds(x, y, mainControls) &&
!resizeCursors.includes(e.target?.style?.cursor) &&
!e.target.id.includes("radix:") &&
e.target.getAttribute("role") !== "dialog"
) {
customCursor.style.display = "block";
} else {
customCursor.style.display = "none";
}
const customCursor = document.getElementById(ids.cursor);
if (
isWithinBounds(x, y, workspace) &&
!isWithinBounds(x, y, zoomControls) &&
!isWithinBounds(x, y, mainControls) &&
!resizeCursors.includes(e.target?.style?.cursor) &&
!e.target.id.includes("radix:") &&
e.target.getAttribute("role") !== "dialog"
) {
customCursor.classList.remove("hidden");
} else {
customCursor.classList.add("hidden");
}
setCursorX(x);
setCursorY(y);
Expand Down

0 comments on commit 9100947

Please sign in to comment.