Skip to content

Commit

Permalink
feat: 支持通过按键 TabShift+Tab 切换分组 (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb authored Jan 14, 2025
1 parent dc23885 commit d726d01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/hooks/useOSKeyPress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const useOSKeyPress: typeof useKeyPress = (...args) => {

handler(event, key);
},
option,
{ exactMatch: true, ...option },
);
};
24 changes: 22 additions & 2 deletions src/pages/Clipboard/Panel/components/Group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HistoryTablePayload> {
Expand All @@ -12,6 +13,7 @@ interface GroupItem extends Partial<HistoryTablePayload> {
const Group = () => {
const { state } = useContext(ClipboardPanelContext);
const { t } = useTranslation();
const [checked, setChecked] = useState("all");

const groupList: GroupItem[] = [
{
Expand Down Expand Up @@ -40,8 +42,6 @@ const Group = () => {
},
];

const [checked, setChecked] = useState(groupList[0].key);

useTauriFocus({
onFocus() {
if (!clipboardStore.window.showAll) return;
Expand All @@ -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;

Expand Down

0 comments on commit d726d01

Please sign in to comment.