Skip to content

Commit 6bdf45f

Browse files
fix(search): require Cmd/Ctrl modifier for K shortcut and show platform-aware label
1 parent 344a00d commit 6bdf45f

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

src/app/[lang]/provider.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
"use client";
12
import { defineI18nUI } from "fumadocs-ui/i18n";
23
import { RootProvider } from "fumadocs-ui/provider/base";
3-
import type { ReactNode } from "react";
4+
import { type ReactNode, useEffect, useState } from "react";
45
import { i18n } from "@/lib/i18n";
56

67
const { provider } = defineI18nUI(i18n, {
@@ -12,6 +13,26 @@ const { provider } = defineI18nUI(i18n, {
1213
},
1314
});
1415

16+
function ShortcutDisplay() {
17+
const [modifier, setModifier] = useState("Ctrl");
18+
19+
useEffect(() => {
20+
const platform =
21+
(navigator as Navigator & { userAgentData?: { platform?: string } })
22+
.userAgentData?.platform ??
23+
navigator.platform ??
24+
"";
25+
setModifier(/Mac|iPhone|iPad|iPod/i.test(platform) ? "⌘" : "Strg");
26+
}, []);
27+
28+
return (
29+
<span className="inline-flex items-center gap-1">
30+
<span>{modifier}</span>
31+
<span>K</span>
32+
</span>
33+
);
34+
}
35+
1536
export function Provider({
1637
children,
1738
lang,
@@ -25,8 +46,9 @@ export function Provider({
2546
enabled: true,
2647
hotKey: [
2748
{
28-
display: "K",
29-
key: "k", // key code, or a function determining whether the key is pressed
49+
display: <ShortcutDisplay />,
50+
key: (e) =>
51+
(e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k",
3052
},
3153
],
3254
}}

0 commit comments

Comments
 (0)