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;