From d13d7737048ef47f3e2523df6c4ce1e1ee0710fb Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Wed, 13 Oct 2021 21:01:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BF=AB=E9=80=9F=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0esc=E5=BF=AB=E9=80=9F=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/QuickSwitcher/index.tsx | 9 ++++++++- web/src/utils/hot-key.ts | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/web/src/components/QuickSwitcher/index.tsx b/web/src/components/QuickSwitcher/index.tsx index 447462b6..72712086 100644 --- a/web/src/components/QuickSwitcher/index.tsx +++ b/web/src/components/QuickSwitcher/index.tsx @@ -5,7 +5,12 @@ import { t } from 'tailchat-shared'; import { PortalAdd, PortalRemove } from '../Portal'; import clsx from 'clsx'; import { useGlobalKeyDown } from '@/hooks/useGlobalKeyDown'; -import { isArrowDown, isArrowUp, isEnterHotkey } from '@/utils/hot-key'; +import { + isArrowDown, + isArrowUp, + isEnterHotkey, + isEscHotkey, +} from '@/utils/hot-key'; import { useQuickSwitcherActionContext } from './useQuickSwitcherActionContext'; import { useQuickSwitcherFilteredActions } from './useQuickSwitcherFilteredActions'; @@ -42,6 +47,8 @@ const QuickSwitcher: React.FC = React.memo(() => { typeof selectedAction.action === 'function' && selectedAction.action(actionContext); handleClose(); + } else if (isEscHotkey(e)) { + handleClose(); } }); diff --git a/web/src/utils/hot-key.ts b/web/src/utils/hot-key.ts index 8195c65d..d214b44e 100644 --- a/web/src/utils/hot-key.ts +++ b/web/src/utils/hot-key.ts @@ -2,6 +2,8 @@ import { isHotkey } from 'is-hotkey'; export const isEnterHotkey = isHotkey('enter'); +export const isEscHotkey = isHotkey('esc'); + export const isQuickSwitcher = isHotkey('mod+k'); export const isArrowUp = isHotkey('up');