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 <Faustino.kialungila@gmail.com>
This commit is contained in:
parent
cb68153a81
commit
cb66adc716
@ -18,7 +18,7 @@
|
|||||||
| Arrow | `A` or `5` | `A` or `5` |
|
| Arrow | `A` or `5` | `A` or `5` |
|
||||||
| Line | `L` or `6` | `L` or `6` |
|
| Line | `L` or `6` | `L` or `6` |
|
||||||
| Text | `T` or `7` | `T` or `7` |
|
| Text | `T` or `7` | `T` or `7` |
|
||||||
| Lock | | |
|
| Lock | `Q` | `Q` |
|
||||||
|
|
||||||
### Editor
|
### Editor
|
||||||
|
|
||||||
|
@ -640,13 +640,16 @@ export class App extends React.Component<any, AppState> {
|
|||||||
);
|
);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (
|
} else if (
|
||||||
shapesShortcutKeys.includes(event.key.toLowerCase()) &&
|
|
||||||
!event.ctrlKey &&
|
!event.ctrlKey &&
|
||||||
!event.altKey &&
|
!event.altKey &&
|
||||||
!event.metaKey &&
|
!event.metaKey &&
|
||||||
this.state.draggingElement === null
|
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) {
|
} else if (event.key === KEYS.SPACE && gesture.pointers.size === 0) {
|
||||||
isHoldingSpace = true;
|
isHoldingSpace = true;
|
||||||
document.documentElement.style.cursor = CURSOR_TYPE.GRABBING;
|
document.documentElement.style.cursor = CURSOR_TYPE.GRABBING;
|
||||||
@ -791,6 +794,15 @@ export class App extends React.Component<any, AppState> {
|
|||||||
this.destroySocketClient();
|
this.destroySocketClient();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
toggleLock = () => {
|
||||||
|
this.setState(prevState => ({
|
||||||
|
elementLocked: !prevState.elementLocked,
|
||||||
|
elementType: prevState.elementLocked
|
||||||
|
? "selection"
|
||||||
|
: prevState.elementType,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
private setElements = (elements: readonly ExcalidrawElement[]) => {
|
private setElements = (elements: readonly ExcalidrawElement[]) => {
|
||||||
globalSceneState.replaceAllElements(elements);
|
globalSceneState.replaceAllElements(elements);
|
||||||
};
|
};
|
||||||
@ -816,6 +828,7 @@ export class App extends React.Component<any, AppState> {
|
|||||||
language={getLanguage()}
|
language={getLanguage()}
|
||||||
onRoomCreate={this.createRoom}
|
onRoomCreate={this.createRoom}
|
||||||
onRoomDestroy={this.destroyRoom}
|
onRoomDestroy={this.destroyRoom}
|
||||||
|
onToggleLock={this.toggleLock}
|
||||||
/>
|
/>
|
||||||
<main>
|
<main>
|
||||||
<canvas
|
<canvas
|
||||||
|
@ -33,6 +33,7 @@ interface LayerUIProps {
|
|||||||
setElements: (elements: readonly ExcalidrawElement[]) => void;
|
setElements: (elements: readonly ExcalidrawElement[]) => void;
|
||||||
onRoomCreate: () => void;
|
onRoomCreate: () => void;
|
||||||
onRoomDestroy: () => void;
|
onRoomDestroy: () => void;
|
||||||
|
onToggleLock: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const LayerUI = React.memo(
|
export const LayerUI = React.memo(
|
||||||
@ -46,6 +47,7 @@ export const LayerUI = React.memo(
|
|||||||
setElements,
|
setElements,
|
||||||
onRoomCreate,
|
onRoomCreate,
|
||||||
onRoomDestroy,
|
onRoomDestroy,
|
||||||
|
onToggleLock,
|
||||||
}: LayerUIProps) => {
|
}: LayerUIProps) => {
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
|
|
||||||
@ -157,14 +159,7 @@ export const LayerUI = React.memo(
|
|||||||
</Island>
|
</Island>
|
||||||
<LockIcon
|
<LockIcon
|
||||||
checked={appState.elementLocked}
|
checked={appState.elementLocked}
|
||||||
onChange={() => {
|
onChange={onToggleLock}
|
||||||
setAppState({
|
|
||||||
elementLocked: !appState.elementLocked,
|
|
||||||
elementType: appState.elementLocked
|
|
||||||
? "selection"
|
|
||||||
: appState.elementType,
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
title={t("toolBar.lock")}
|
title={t("toolBar.lock")}
|
||||||
isButton={isMobile}
|
isButton={isMobile}
|
||||||
/>
|
/>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import "./ToolIcon.scss";
|
import "./ToolIcon.scss";
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { getShortcutKey } from "../utils";
|
||||||
|
|
||||||
type LockIconSize = "s" | "m";
|
type LockIconSize = "s" | "m";
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ export function LockIcon(props: LockIconProps) {
|
|||||||
className={`ToolIcon ToolIcon__lock ${
|
className={`ToolIcon ToolIcon__lock ${
|
||||||
props.isButton ? "ToolIcon_type_button" : "ToolIcon_type_floating"
|
props.isButton ? "ToolIcon_type_button" : "ToolIcon_type_floating"
|
||||||
} ${sizeCn}`}
|
} ${sizeCn}`}
|
||||||
title={props.title}
|
title={`${props.title} ${getShortcutKey("Q")}`}
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
className="ToolIcon_type_checkbox"
|
className="ToolIcon_type_checkbox"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user