Skip to content

Commit

Permalink
feat: macos 支持 command w 关闭窗口
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb committed Aug 7, 2024
1 parent ffaf775 commit 11a5476
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
8 changes: 1 addition & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 58,7 @@ const App = () => {
open(href);
});

useEventListener("keydown", (event) => {
if (event.code === "Escape") {
event.preventDefault();

hideWindow();
}
});
useOSKeyPress(["esc", "meta.w"], hideWindow);

return (
<ConfigProvider
Expand Down
19 changes: 19 additions & 0 deletions src/hooks/useOSKeyPress.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,19 @@
export const useOSKeyPress: typeof useKeyPress = (
keyFilter,
handler,
option,
) => {
useKeyPress(
keyFilter,
(event, key) => {
const { metaKey, ctrlKey } = event;

if ((metaKey && !isMac()) || (ctrlKey && isMac())) return;

event.preventDefault();

handler(event, key);
},
option,
);
};
4 changes: 1 addition & 3 deletions src/pages/Clipboard/History/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 44,7 @@ const Search: FC<InputProps> = (props) => {
},
);

useKeyPress(["meta.f", "ctrl.f"], (event) => {
event.preventDefault();

useOSKeyPress(["meta.f", "ctrl.f"], () => {
inputRef.current?.focus();
});

Expand Down

0 comments on commit 11a5476

Please sign in to comment.