mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Add event listeners for shapes shortcuts
This commit is contained in:
parent
4626d0d21d
commit
4730545c06
1 changed files with 13 additions and 0 deletions
|
@ -502,6 +502,17 @@ const SHAPES = [
|
|||
}
|
||||
];
|
||||
|
||||
const shapesShortcutKeys = SHAPES.map(shape => shape.label[0].toLowerCase());
|
||||
|
||||
function findElementByKey(key: string) {
|
||||
const defaultElement = "selection";
|
||||
return SHAPES.reduce((element, shape) => {
|
||||
if (shape.value[0] !== key) return element;
|
||||
|
||||
return shape.value;
|
||||
}, defaultElement);
|
||||
}
|
||||
|
||||
function isArrowKey(keyCode: string) {
|
||||
return (
|
||||
keyCode === KEYS.ARROW_LEFT ||
|
||||
|
@ -572,6 +583,8 @@ class App extends React.Component<{}, AppState> {
|
|||
});
|
||||
this.forceUpdate();
|
||||
event.preventDefault();
|
||||
} else if (shapesShortcutKeys.includes(event.key.toLowerCase())) {
|
||||
this.setState({ elementType: findElementByKey(event.key) });
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue