fix: cursor being leaked outside of canvas (#3161)
This commit is contained in:
24
src/utils.ts
24
src/utils.ts
@ -160,15 +160,29 @@ export const removeSelection = () => {
|
||||
|
||||
export const distance = (x: number, y: number) => Math.abs(x - y);
|
||||
|
||||
export const resetCursor = () => {
|
||||
document.documentElement.style.cursor = "";
|
||||
export const resetCursor = (canvas: HTMLCanvasElement | null) => {
|
||||
if (canvas) {
|
||||
canvas.style.cursor = "";
|
||||
}
|
||||
};
|
||||
|
||||
export const setCursorForShape = (shape: string) => {
|
||||
export const setCursor = (canvas: HTMLCanvasElement | null, cursor: string) => {
|
||||
if (canvas) {
|
||||
canvas.style.cursor = cursor;
|
||||
}
|
||||
};
|
||||
|
||||
export const setCursorForShape = (
|
||||
canvas: HTMLCanvasElement | null,
|
||||
shape: string,
|
||||
) => {
|
||||
if (!canvas) {
|
||||
return;
|
||||
}
|
||||
if (shape === "selection") {
|
||||
resetCursor();
|
||||
resetCursor(canvas);
|
||||
} else {
|
||||
document.documentElement.style.cursor = CURSOR_TYPE.CROSSHAIR;
|
||||
canvas.style.cursor = CURSOR_TYPE.CROSSHAIR;
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user