Skip to content

Commit

Permalink
Add numeric hotkeys (excalidraw#380)
Browse files Browse the repository at this point in the history
* Add numeric hotkeys

* Nit: add space after comma
  • Loading branch information
jillesme authored and vjeux committed Jan 16, 2020
1 parent a3aa57d commit 2a8e562
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,14 @@ export class App extends React.Component<{}, AppState> {
private renderShapesSwitcher() {
return (
<>
{SHAPES.map(({ value, icon }) => (
{SHAPES.map(({ value, icon }, index) => (
<ToolIcon
key={value}
type="radio"
icon={icon}
checked={this.state.elementType === value}
name="editor-current-shape"
title={`${capitalizeString(value)}${capitalizeString(value)[0]}`}
title={`${capitalizeString(value)}${capitalizeString(value)[0]}, ${index + 1}`}
onChange={() => {
this.setState({ elementType: value });
elements = clearSelection(elements);
Expand Down
8 changes: 5 additions & 3 deletions src/shapes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ export const SHAPES = [
}
];

export const shapesShortcutKeys = SHAPES.map(shape => shape.value[0]);
export const shapesShortcutKeys = SHAPES.map((shape, index) => [
shape.value[0], (index + 1).toString()]
).flat(1);

export function findShapeByKey(key: string) {
const defaultElement = "selection";
return SHAPES.reduce((element, shape) => {
if (shape.value[0] !== key) return element;
return SHAPES.reduce((element, shape, index) => {
if (shape.value[0] !== key && key !== (index + 1).toString()) return element;

return shape.value;
}, defaultElement);
Expand Down

0 comments on commit 2a8e562

Please sign in to comment.