Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

feat(settings): add keyboard shortcut (Cmd+,/Ctrl+,) to open settings

Yujing Zhenge08ea4177e7e
diff --git a/src/App.tsx b/src/App.tsx
index 709f3fa4..253403ba 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -13,6 +13,7 @@ import { getLastProject, getRecentProjects, saveLastProject, loadLlmConfig, load
import { loadReviewItems, loadLintItems, loadChatHistory, loadChatPreferences } from "@/lib/persist"
import { setupAutoSave } from "@/lib/auto-save"
import { startClipWatcher } from "@/lib/clip-watcher"
+import { useGlobalShortcut } from "@/hooks/use-global-shortcut"
import { AppLayout } from "@/components/layout/app-layout"
import { WelcomeScreen } from "@/components/project/welcome-screen"
import { CreateProjectDialog } from "@/components/project/create-project-dialog"
@@ -125,6 +126,12 @@ function App() {
startClipWatcher()
}, [])
+ // Register global keyboard shortcuts
+ // Cmd+, on macOS or Ctrl+, on Windows/Linux opens settings
+ useGlobalShortcut({
+ ",": () => setActiveView("settings"),
+ })
+
useEffect(() => {
// Apply interface zoom globally, including welcome/settings screens. We
// scale the rem base instead of using transform: scale() so layout and
diff --git a/src/components/layout/icon-sidebar.tsx b/src/components/layout/icon-sidebar.tsx
index 2044d9e3..74b9d977 100644
--- a/src/components/layout/icon-sidebar.tsx
+++ b/src/components/layout/icon-sidebar.tsx
@@ -189,6 +189,7 @@ export function IconSidebar({ onSwitchProject }: IconSidebarProps) {
</TooltipTrigger>
<TooltipContent side="right">
{t("nav.settings")}
+ {t("nav.settingsShortcut")}
{updateAvailable ? t("nav.updateAvailableSuffix") : ""}
</TooltipContent>
</Tooltip>
diff --git a/src/hooks/use-global-shortcut.ts b/src/hooks/use-global-shortcut.ts
new file mode 100644
index 00000000..12cf47ed
--- /dev/null
+++ b/src/hooks/use-global-shortcut.ts
@@ -0,0 +1,117 @@
+/**
+ * React hook for handling global keyboard shortcuts.
+ *
+ * Registers window-level keyboard event listeners that trigger callbacks
+ * when specific key combinations are pressed. Shortcuts are global within
+ * the application (work from any view) but are automatically suppressed when
+ * the user is typing in text input fields to avoid interference.
+ *
+ * @example
+ * ```ts
+ * useGlobalShortcut({
+ * ",": () => setActiveView("settings"),
+ * })
+ * ```
+ *
+ * Platform conventions:
+ * - macOS: Cmd (⌘) + key
+ * - Windows/Linux: Ctrl + key
+ */
+
+import { useEffect, useCallback } from "react"
+
+export interface ShortcutMap {
+ [key: string]: () => void
+}
+
+/**
+ * Check if an element is a text input field that should suppress global shortcuts.
+ *
+ * Returns true for:
+ * - <input> elements (except checkboxes/radio/buttons)
+ * - <textarea> elements
+ * - Elements with contentEditable="true"
+ * - Elements with role="textbox"
+ */
+function isTextInput(element: HTMLElement | null): boolean {
+ if (!element) return false
+
+ const tag = element.tagName.toLowerCase()
+ if (tag === "textarea") return true
+ if (tag === "input") {
+ const inputType = (element as HTMLInputElement).type
+ // Allow shortcuts on checkboxes, radio buttons, and buttons
+ return !["checkbox", "radio", "submit", "button", "reset"].includes(inputType)
+ }
+ if (element.isContentEditable) return true
+ if (element.getAttribute("role") === "textbox") return true
+
+ return false
+}
+
+/**
+ * Check if the event has the appropriate modifier key for the current platform.
+ *
+ * - macOS: Requires event.metaKey (Cmd)
+ * - Windows/Linux: Requires event.ctrlKey
+ */
+function hasPlatformModifierKey(event: KeyboardEvent): boolean {
+ // Detect platform via user agent (Tauri sets this correctly)
+ const isMac = typeof navigator !== "undefined" && /Mac OS X/.test(navigator.userAgent)
+
+ if (isMac) {
+ return event.metaKey
+ } else {
+ return event.ctrlKey
+ }
+}
+
+/**
+ * Register global keyboard shortcuts.
+ *
+ * @param shortcuts - Map of key names to callback functions
+ * @param deps - Optional dependency array to re-register shortcuts when values change
+ *
+ * Keys should be lowercase event.key values (e.g., "," for comma, "s" for S key).
+ *
+ * Shortcuts are suppressed when:
+ * - User is typing in a text input field
+ * - User is composing text via IME (Chinese/Japanese/Korean input methods)
+ */
+export function useGlobalShortcut(shortcuts: ShortcutMap, deps: unknown[] = []): void {
+ const handleKeyDown = useCallback(
+ (event: KeyboardEvent) => {
+ // Suppress shortcuts when user is typing in a text input field
+ if (isTextInput(document.activeElement as HTMLElement | null)) {
+ return
+ }
+
+ // Suppress shortcuts during IME composition (e.g., typing Chinese characters)
+ // keyCode 229 is the legacy "IME activity" signal
+ if (event.keyCode === 229) {
+ return
+ }
+
+ // Check if the pressed key has a registered shortcut
+ const key = event.key.toLowerCase()
+ const callback = shortcuts[key]
+ if (!callback) return
+
+ // Require platform-appropriate modifier key (Cmd on macOS, Ctrl on others)
+ // This prevents triggering shortcuts during normal typing
+ if (!hasPlatformModifierKey(event)) return
+
+ // Prevent default browser behavior and execute the callback
+ event.preventDefault()
+ callback()
+ },
+ [shortcuts],
+ )
+
+ useEffect(() => {
+ window.addEventListener("keydown", handleKeyDown)
+ return () => {
+ window.removeEventListener("keydown", handleKeyDown)
+ }
+ }, [handleKeyDown, ...deps])
+}
diff --git a/src/i18n/en.json b/src/i18n/en.json
index d3a19f9b..5c53859d 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -26,6 +26,7 @@
"review": "Review",
"skills": "Skills",
"settings": "Settings",
+ "settingsShortcut": " (⌘,)",
"switchProject": "Switch Project",
"updateAvailable": "Update available",
"updateAvailableSuffix": " · update"
diff --git a/src/i18n/zh.json b/src/i18n/zh.json
index dc32ee25..0eee43d5 100644
--- a/src/i18n/zh.json
+++ b/src/i18n/zh.json
@@ -26,6 +26,7 @@
"review": "待审阅",
"skills": "Skills",
"settings": "设置",
+ "settingsShortcut": " (⌘,)",
"switchProject": "切换项目",
"updateAvailable": "有可用更新",
"updateAvailableSuffix": " · 有更新"