From bef279417e175a761421b00022773f0c3f8b4685 Mon Sep 17 00:00:00 2001 From: Bakhtiiar Muzakparov Date: Wed, 22 Jan 2020 19:36:08 +0600 Subject: [PATCH] fix: cursor on keyboard tool toggle (#482) * update events for GH actions to include PRs * fix: cursor on keyboard tool toggle * fix: change cursor type to constant * fix: swap condition Co-authored-by: David Luzar --- src/index.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index f8bfd725..dc7b15a3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -95,6 +95,10 @@ function resetCursor() { const ELEMENT_SHIFT_TRANSLATE_AMOUNT = 5; const ELEMENT_TRANSLATE_AMOUNT = 1; const TEXT_TO_CENTER_SNAP_THRESHOLD = 30; +const CURSOR_TYPE = { + TEXT: "text", + CROSSHAIR: "crosshair" +}; let lastCanvasWidth = -1; let lastCanvasHeight = -1; @@ -273,6 +277,8 @@ export class App extends React.Component { return; } + const shape = findShapeByKey(event.key); + if (isArrowKey(event.key)) { const step = event.shiftKey ? ELEMENT_SHIFT_TRANSLATE_AMOUNT @@ -298,7 +304,12 @@ export class App extends React.Component { !event.metaKey && this.state.draggingElement === null ) { - this.setState({ elementType: findShapeByKey(event.key) }); + if (shape === "text") { + document.documentElement.style.cursor = CURSOR_TYPE.TEXT; + } else { + document.documentElement.style.cursor = CURSOR_TYPE.CROSSHAIR; + } + this.setState({ elementType: shape }); } else if (event[KEYS.META] && event.code === "KeyZ") { if (event.shiftKey) { // Redo action @@ -483,7 +494,7 @@ export class App extends React.Component { this.setState({ elementType: value }); elements = clearSelection(elements); document.documentElement.style.cursor = - value === "text" ? "text" : "crosshair"; + value === "text" ? CURSOR_TYPE.TEXT : CURSOR_TYPE.CROSSHAIR; this.forceUpdate(); }} >