fix(desktop): keep profile shortcut out of editors

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Thomas Petersen
2026-06-03 16:09:25 -04:00
parent 3ff2f1209b
commit eb222144de
2 changed files with 73 additions and 28 deletions

View File

@@ -12,6 +12,7 @@ import { AppTopChrome } from "@/app/AppTopChrome";
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
import { useBackForwardControls } from "@/app/navigation/useBackForwardControls";
import { useMarkAsReadShortcuts } from "@/app/useMarkAsReadShortcuts";
import { useSettingsShortcuts } from "@/app/useSettingsShortcuts";
import { useWebviewZoomShortcuts } from "@/app/useWebviewZoomShortcuts";
import {
channelsQueryKey,
@@ -588,34 +589,12 @@ export function AppShell() {
settingsOpen,
]);
React.useLayoutEffect(() => {
function handleKeyDown(event: KeyboardEvent) {
const hasSettingsShortcutModifiers =
hasPrimaryShortcutModifier(event) && !event.altKey && !event.shiftKey;
const isSettingsShortcut =
hasSettingsShortcutModifiers &&
(event.key === "," || event.code === "Comma");
const isProfileShortcut =
hasSettingsShortcutModifiers && event.key.toLowerCase() === "u";
if (!isSettingsShortcut && !isProfileShortcut) {
return;
}
event.preventDefault();
if (settingsOpen && (!isProfileShortcut || settingsMode === "profile")) {
handleCloseSettings();
return;
}
handleOpenSettings(isProfileShortcut ? "profile" : undefined);
}
window.addEventListener("keydown", handleKeyDown);
return () => {
window.removeEventListener("keydown", handleKeyDown);
};
}, [handleCloseSettings, handleOpenSettings, settingsMode, settingsOpen]);
useSettingsShortcuts({
mode: settingsMode,
onClose: handleCloseSettings,
onOpenSettings: handleOpenSettings,
open: settingsOpen,
});
useMarkAsReadShortcuts({
activeChannelId: activeChannel?.id ?? null,

View File

@@ -0,0 +1,66 @@
import * as React from "react";
import { hasPrimaryShortcutModifier } from "@/shared/lib/platform";
const EDITABLE_SHORTCUT_TARGET_SELECTOR =
'input, textarea, select, [contenteditable="true"]';
type SettingsMode = "profile" | "preferences";
type UseSettingsShortcutsOptions = {
mode: SettingsMode;
onClose: () => void;
onOpenSettings: (section?: "profile") => void;
open: boolean;
};
function isEditableShortcutTarget(event: KeyboardEvent) {
const target = event.target;
return (
target instanceof Element &&
target.closest(EDITABLE_SHORTCUT_TARGET_SELECTOR)
);
}
export function useSettingsShortcuts({
mode,
onClose,
onOpenSettings,
open,
}: UseSettingsShortcutsOptions) {
React.useLayoutEffect(() => {
function handleKeyDown(event: KeyboardEvent) {
const hasSettingsShortcutModifiers =
hasPrimaryShortcutModifier(event) && !event.altKey && !event.shiftKey;
const isSettingsShortcut =
hasSettingsShortcutModifiers &&
(event.key === "," || event.code === "Comma");
const isProfileShortcut =
hasSettingsShortcutModifiers &&
event.key.toLowerCase() === "u" &&
!isEditableShortcutTarget(event);
if (!isSettingsShortcut && !isProfileShortcut) {
return;
}
event.preventDefault();
if (open && (!isProfileShortcut || mode === "profile")) {
onClose();
return;
}
if (isProfileShortcut) {
onOpenSettings("profile");
return;
}
onOpenSettings();
}
window.addEventListener("keydown", handleKeyDown);
return () => {
window.removeEventListener("keydown", handleKeyDown);
};
}, [mode, onClose, onOpenSettings, open]);
}