From cb66adc7161ee340f6a52464bbcdb6b7ecac647f Mon Sep 17 00:00:00 2001 From: Sanghyeon Lee Date: Thu, 19 Mar 2020 03:29:59 +0900 Subject: [PATCH] Add a Shortcut for Toggling Shape Lock (#1005) * Update shortcuts.md for Lock * Add 'Q' as a shortcut for toggling shape lock * Add shortcut to LockIcon title * use event.key instead Co-authored-by: Faustino Kialungila --- docs/shortcuts.md | 2 +- src/components/App.tsx | 17 +++++++++++++++-- src/components/LayerUI.tsx | 11 +++-------- src/components/LockIcon.tsx | 3 ++- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/docs/shortcuts.md b/docs/shortcuts.md index aaa934fa..d4c674d9 100644 --- a/docs/shortcuts.md +++ b/docs/shortcuts.md @@ -18,7 +18,7 @@ | Arrow | `A` or `5` | `A` or `5` | | Line | `L` or `6` | `L` or `6` | | Text | `T` or `7` | `T` or `7` | -| Lock | | | +| Lock | `Q` | `Q` | ### Editor diff --git a/src/components/App.tsx b/src/components/App.tsx index 6cdec1ca..19217735 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -640,13 +640,16 @@ export class App extends React.Component { ); event.preventDefault(); } else if ( - shapesShortcutKeys.includes(event.key.toLowerCase()) && !event.ctrlKey && !event.altKey && !event.metaKey && this.state.draggingElement === null ) { - this.selectShapeTool(shape); + if (shapesShortcutKeys.includes(event.key.toLowerCase())) { + this.selectShapeTool(shape); + } else if (event.key === "q") { + this.toggleLock(); + } } else if (event.key === KEYS.SPACE && gesture.pointers.size === 0) { isHoldingSpace = true; document.documentElement.style.cursor = CURSOR_TYPE.GRABBING; @@ -791,6 +794,15 @@ export class App extends React.Component { this.destroySocketClient(); }; + toggleLock = () => { + this.setState(prevState => ({ + elementLocked: !prevState.elementLocked, + elementType: prevState.elementLocked + ? "selection" + : prevState.elementType, + })); + }; + private setElements = (elements: readonly ExcalidrawElement[]) => { globalSceneState.replaceAllElements(elements); }; @@ -816,6 +828,7 @@ export class App extends React.Component { language={getLanguage()} onRoomCreate={this.createRoom} onRoomDestroy={this.destroyRoom} + onToggleLock={this.toggleLock} />
void; onRoomCreate: () => void; onRoomDestroy: () => void; + onToggleLock: () => void; } export const LayerUI = React.memo( @@ -46,6 +47,7 @@ export const LayerUI = React.memo( setElements, onRoomCreate, onRoomDestroy, + onToggleLock, }: LayerUIProps) => { const isMobile = useIsMobile(); @@ -157,14 +159,7 @@ export const LayerUI = React.memo( { - setAppState({ - elementLocked: !appState.elementLocked, - elementType: appState.elementLocked - ? "selection" - : appState.elementType, - }); - }} + onChange={onToggleLock} title={t("toolBar.lock")} isButton={isMobile} /> diff --git a/src/components/LockIcon.tsx b/src/components/LockIcon.tsx index 014dad5f..e7aedd8f 100644 --- a/src/components/LockIcon.tsx +++ b/src/components/LockIcon.tsx @@ -1,6 +1,7 @@ import "./ToolIcon.scss"; import React from "react"; +import { getShortcutKey } from "../utils"; type LockIconSize = "s" | "m"; @@ -48,7 +49,7 @@ export function LockIcon(props: LockIconProps) { className={`ToolIcon ToolIcon__lock ${ props.isButton ? "ToolIcon_type_button" : "ToolIcon_type_floating" } ${sizeCn}`} - title={props.title} + title={`${props.title} ${getShortcutKey("Q")}`} >