From 0cf3aad910514262b2127c40317c3aca79b43310 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 10 Dec 2020 21:37:21 -0600 Subject: [PATCH] Add keyboard shortcuts to action buttons Just run and stop button have keys assigned for now. --- src/components/ActionButton.tsx | 42 +++++++++++++++++++++++++++++---- src/components/DocsButton.tsx | 3 ++- src/components/ReplButton.tsx | 3 ++- src/components/RunButton.tsx | 3 ++- src/components/SaveAsButton.tsx | 3 ++- src/components/StopButton.tsx | 3 ++- src/components/Terminal.tsx | 4 ++++ src/components/Toolbar.tsx | 4 ++-- tsconfig.json | 1 + 9 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/components/ActionButton.tsx b/src/components/ActionButton.tsx index 050b3bf4..3f7a9c13 100644 --- a/src/components/ActionButton.tsx +++ b/src/components/ActionButton.tsx @@ -1,7 +1,9 @@ // SPDX-License-Identifier: MIT // Copyright (c) 2020 The Pybricks Authors -import { Button, Intent, Position, Tooltip } from '@blueprintjs/core'; +import { Button, Hotkey, Hotkeys, Intent, Position, Tooltip } from '@blueprintjs/core'; +// importing this way due to https://github.com/palantir/blueprint/issues/3604 +import { HotkeysTarget } from '@blueprintjs/core/lib/esnext/components/hotkeys/hotkeysTarget'; import { WithI18nProps, withI18n } from '@shopify/react-i18n'; import React from 'react'; import { TooltipId } from './button-i18n'; @@ -10,6 +12,8 @@ import en from './button-i18n.en.json'; export interface ActionButtonProps { /** A unique id for each instance. */ readonly id: string; + /** Keyboard shortcut. */ + readonly keyboardShortcut?: string; /** Tooltip text that appears when hovering over the button. */ readonly tooltip: TooltipId; /** Icon shown on the button. */ @@ -22,14 +26,19 @@ export interface ActionButtonProps { type Props = ActionButtonProps & WithI18nProps; +@HotkeysTarget class ActionButton extends React.Component { + private buttonRef: React.RefObject