From d726d01ab863ffc8e8c091a805c70ea32af5e426 Mon Sep 17 00:00:00 2001 From: ayangweb <75017711+ayangweb@users.noreply.github.com> Date: Tue, 14 Jan 2025 22:05:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E6=8C=89=E9=94=AE=20`Tab`=20=E5=92=8C=20`Shift+Tab`=20?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=88=86=E7=BB=84=20(#940)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useOSKeyPress.ts | 2 +- .../Panel/components/Group/index.tsx | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/hooks/useOSKeyPress.ts b/src/hooks/useOSKeyPress.ts index 658e58e30e..9fe4bc5046 100644 --- a/src/hooks/useOSKeyPress.ts +++ b/src/hooks/useOSKeyPress.ts @@ -12,6 +12,6 @@ export const useOSKeyPress: typeof useKeyPress = (...args) => { handler(event, key); }, - option, + { exactMatch: true, ...option }, ); }; diff --git a/src/pages/Clipboard/Panel/components/Group/index.tsx b/src/pages/Clipboard/Panel/components/Group/index.tsx index ca971f38f5..88728981ed 100644 --- a/src/pages/Clipboard/Panel/components/Group/index.tsx +++ b/src/pages/Clipboard/Panel/components/Group/index.tsx @@ -2,6 +2,7 @@ import Scrollbar from "@/components/Scrollbar"; import type { HistoryTablePayload } from "@/types/database"; import { Flex, Tag } from "antd"; import clsx from "clsx"; +import { last } from "lodash-es"; import { ClipboardPanelContext } from "../.."; interface GroupItem extends Partial { @@ -12,6 +13,7 @@ interface GroupItem extends Partial { const Group = () => { const { state } = useContext(ClipboardPanelContext); const { t } = useTranslation(); + const [checked, setChecked] = useState("all"); const groupList: GroupItem[] = [ { @@ -40,8 +42,6 @@ const Group = () => { }, ]; - const [checked, setChecked] = useState(groupList[0].key); - useTauriFocus({ onFocus() { if (!clipboardStore.window.showAll) return; @@ -50,6 +50,26 @@ const Group = () => { }, }); + useOSKeyPress("tab", () => { + const index = groupList.findIndex((item) => item.key === checked); + + if (index === groupList.length - 1) { + handleChange(groupList[0]); + } else { + handleChange(groupList[index + 1]); + } + }); + + useOSKeyPress("shift.tab", () => { + const index = groupList.findIndex((item) => item.key === checked); + + if (index === 0) { + handleChange(last(groupList)!); + } else { + handleChange(groupList[index - 1]); + } + }); + const handleChange = (item: GroupItem) => { const { key, group, favorite } = item;