fix: cursor being leaked outside of canvas (#3161)

This commit is contained in:
David Luzar 2021-03-03 14:04:02 +01:00 committed by GitHub
parent f295ba98c5
commit c77c9ce65a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 69 additions and 52 deletions

View file

@ -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;
}
};