Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(preferences): allow disable hotkeys (#39573)

Charis3eb7da776666
diff --git a/apps/studio/components/interfaces/Account/Preferences/HotkeySettings.tsx b/apps/studio/components/interfaces/Account/Preferences/HotkeySettings.tsx
new file mode 100644
index 00000000000..b25760ce8be
--- /dev/null
+++ b/apps/studio/components/interfaces/Account/Preferences/HotkeySettings.tsx
@@ -0,0 +1,68 @@
+import { LOCAL_STORAGE_KEYS } from 'common'
+import Panel from 'components/ui/Panel'
+import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
+import { KeyboardShortcut, Toggle } from 'ui'
+
+export const HotkeySettings = () => {
+ const [inlineEditorEnabled, setInlineEditorEnabled] = useLocalStorageQuery(
+ LOCAL_STORAGE_KEYS.HOTKEY_INLINE_EDITOR,
+ true
+ )
+ const [commandMenuEnabled, setCommandMenuEnabled] = useLocalStorageQuery(
+ LOCAL_STORAGE_KEYS.HOTKEY_COMMAND_MENU,
+ true
+ )
+ const [aiAssistantEnabled, setAiAssistantEnabled] = useLocalStorageQuery(
+ LOCAL_STORAGE_KEYS.HOTKEY_AI_ASSISTANT,
+ true
+ )
+
+ return (
+ <Panel
+ title={
+ <div>
+ <h5 id="keyboard-shortcuts">Keyboard shortcuts</h5>
+ <p className="text-sm text-foreground-lighter">
+ Choose which shortcuts stay active while working in the dashboard
+ </p>
+ </div>
+ }
+ >
+ <Panel.Content className="space-y-3">
+ <Toggle
+ checked={commandMenuEnabled}
+ onChange={() => setCommandMenuEnabled(!commandMenuEnabled)}
+ label={
+ <div className="flex items-center gap-x-2">
+ <KeyboardShortcut keys={['Meta', 'k']} />
+ <span>Command menu</span>
+ </div>
+ }
+ descriptionText="Toggles the global command menu."
+ />
+ <Toggle
+ checked={aiAssistantEnabled}
+ onChange={() => setAiAssistantEnabled(!aiAssistantEnabled)}
+ label={
+ <div className="flex items-center gap-x-2">
+ <KeyboardShortcut keys={['Meta', 'i']} />
+ <span>AI Assistant</span>
+ </div>
+ }
+ descriptionText="Toggles the AI Assistant panel."
+ />
+ <Toggle
+ checked={inlineEditorEnabled}
+ onChange={() => setInlineEditorEnabled(!inlineEditorEnabled)}
+ label={
+ <div className="flex items-center gap-x-2">
+ <KeyboardShortcut keys={['Meta', 'e']} />
+ <span>Inline SQL Editor</span>
+ </div>
+ }
+ descriptionText="Toggles the inline SQL editor in a side panel"
+ />
+ </Panel.Content>
+ </Panel>
+ )
+}
diff --git a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsLayout.tsx b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsLayout.tsx
index 69ffaba644b..14635287b93 100644
--- a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsLayout.tsx
+++ b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsLayout.tsx
@@ -5,7 +5,7 @@ import { useIsAdvisorRulesEnabled } from 'components/interfaces/App/FeaturePrevi
import { ProductMenu } from 'components/ui/ProductMenu'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { withAuth } from 'hooks/misc/withAuth'
-import ProjectLayout from '../ProjectLayout/ProjectLayout'
+import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
import { generateAdvisorsMenu } from './AdvisorsMenu.utils'
export interface AdvisorsLayoutProps {
diff --git a/apps/studio/components/layouts/AppLayout/AssistantButton.tsx b/apps/studio/components/layouts/AppLayout/AssistantButton.tsx
index 93254be01c4..afe8bcba9fd 100644
--- a/apps/studio/components/layouts/AppLayout/AssistantButton.tsx
+++ b/apps/studio/components/layouts/AppLayout/AssistantButton.tsx
@@ -1,10 +1,15 @@
+import { LOCAL_STORAGE_KEYS } from 'common'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
+import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
-import { AiIconAnimation } from 'ui'
-import { KeyboardShortcut } from 'ui'
+import { AiIconAnimation, KeyboardShortcut } from 'ui'
export const AssistantButton = () => {
const snap = useAiAssistantStateSnapshot()
+ const [isAIAssistantHotkeyEnabled] = useLocalStorageQuery<boolean>(
+ LOCAL_STORAGE_KEYS.HOTKEY_AI_ASSISTANT,
+ true
+ )
return (
<ButtonTooltip
@@ -20,7 +25,7 @@ export const AssistantButton = () => {
text: (
<div className="flex items-center gap-4">
<span>AI Assistant</span>
- <KeyboardShortcut keys={['Meta', 'i']} />
+ {isAIAssistantHotkeyEnabled && <KeyboardShortcut keys={['Meta', 'i']} />}
</div>
),
},
diff --git a/apps/studio/components/layouts/AppLayout/InlineEditorButton.tsx b/apps/studio/components/layouts/AppLayout/InlineEditorButton.tsx
index d447221b08b..57c39df7a54 100644
--- a/apps/studio/components/layouts/AppLayout/InlineEditorButton.tsx
+++ b/apps/studio/components/layouts/AppLayout/InlineEditorButton.tsx
@@ -2,7 +2,13 @@ import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { SqlEditor } from 'icons'
import { KeyboardShortcut } from 'ui'
-export const InlineEditorButton = ({ onClick }: { onClick: () => void }) => {
+export const InlineEditorButton = ({
+ onClick,
+ showShortcut = true,
+}: {
+ onClick: () => void
+ showShortcut?: boolean
+}) => {
return (
<ButtonTooltip
type="text"
@@ -15,7 +21,7 @@ export const InlineEditorButton = ({ onClick }: { onClick: () => void }) => {
text: (
<div className="flex items-center gap-4">
<span>SQL Editor</span>
- <KeyboardShortcut keys={['Meta', 'e']} />
+ {showShortcut && <KeyboardShortcut keys={['Meta', 'e']} />}
</div>
),
},
diff --git a/apps/studio/components/layouts/AuthLayout/AuthLayout.tsx b/apps/studio/components/layouts/AuthLayout/AuthLayout.tsx
index 8fa1483de02..70c4cfe7b3d 100644
--- a/apps/studio/components/layouts/AuthLayout/AuthLayout.tsx
+++ b/apps/studio/components/layouts/AuthLayout/AuthLayout.tsx
@@ -6,7 +6,7 @@ import { ProductMenu } from 'components/ui/ProductMenu'
import { useAuthConfigPrefetch } from 'data/auth/auth-config-query'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { withAuth } from 'hooks/misc/withAuth'
-import ProjectLayout from '../ProjectLayout/ProjectLayout'
+import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
import { generateAuthMenu } from './AuthLayout.utils'
import { useFlag } from 'common'
diff --git a/apps/studio/components/layouts/BranchLayout/BranchLayout.tsx b/apps/studio/components/layouts/BranchLayout/BranchLayout.tsx
index 9ce4fb7d2f7..1f8fd8c88c3 100644
--- a/apps/studio/components/layouts/BranchLayout/BranchLayout.tsx
+++ b/apps/studio/components/layouts/BranchLayout/BranchLayout.tsx
@@ -5,7 +5,7 @@ import { useParams } from 'common'
import { GitHubStatus } from 'components/interfaces/Settings/Integrations/GithubIntegration/GitHubStatus'
import { ProductMenu } from 'components/ui/ProductMenu'
import { withAuth } from 'hooks/misc/withAuth'
-import ProjectLayout from '../ProjectLayout/ProjectLayout'
+import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
import { generateBranchMenu } from './BranchLayout.utils'
const BranchProductMenu = () => {
diff --git a/apps/studio/components/layouts/DatabaseLayout/DatabaseLayout.tsx b/apps/studio/components/layouts/DatabaseLayout/DatabaseLayout.tsx
index 59f74122a4f..0be07584daa 100644
--- a/apps/studio/components/layouts/DatabaseLayout/DatabaseLayout.tsx
+++ b/apps/studio/components/layouts/DatabaseLayout/DatabaseLayout.tsx
@@ -9,7 +9,7 @@ import { useProjectAddonsQuery } from 'data/subscriptions/project-addons-query'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { withAuth } from 'hooks/misc/withAuth'
-import ProjectLayout from '../ProjectLayout/ProjectLayout'
+import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
import { generateDatabaseMenu } from './DatabaseMenu.utils'
export interface DatabaseLayoutProps {
diff --git a/apps/studio/components/layouts/DocsLayout/DocsLayout.tsx b/apps/studio/components/layouts/DocsLayout/DocsLayout.tsx
index 9c6169a5e2c..d34e0682975 100644
--- a/apps/studio/components/layouts/DocsLayout/DocsLayout.tsx
+++ b/apps/studio/components/layouts/DocsLayout/DocsLayout.tsx
@@ -10,7 +10,7 @@ import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { withAuth } from 'hooks/misc/withAuth'
import { PROJECT_STATUS } from 'lib/constants'
-import ProjectLayout from '../ProjectLayout/ProjectLayout'
+import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
import { generateDocsMenu } from './DocsLayout.utils'
function DocsLayout({ title, children }: { title: string; children: ReactElement }) {
diff --git a/apps/studio/components/layouts/EdgeFunctionsLayout/EdgeFunctionDetailsLayout.tsx b/apps/studio/components/layouts/EdgeFunctionsLayout/EdgeFunctionDetailsLayout.tsx
index 998ab9bf59d..2f9087594e3 100644
--- a/apps/studio/components/layouts/EdgeFunctionsLayout/EdgeFunctionDetailsLayout.tsx
+++ b/apps/studio/components/layouts/EdgeFunctionsLayout/EdgeFunctionDetailsLayout.tsx
@@ -27,7 +27,7 @@ import {
Separator,
} from 'ui'
import { Input } from 'ui-patterns/DataInputs/Input'
-import ProjectLayout from '../ProjectLayout/ProjectLayout'
+import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
import EdgeFunctionsLayout from './EdgeFunctionsLayout'
interface EdgeFunctionDetailsLayoutProps {
diff --git a/apps/studio/components/layouts/EdgeFunctionsLayout/EdgeFunctionsLayout.tsx b/apps/studio/components/layouts/EdgeFunctionsLayout/EdgeFunctionsLayout.tsx
index 2f70bebd87e..7816e4c0e3b 100644
--- a/apps/studio/components/layouts/EdgeFunctionsLayout/EdgeFunctionsLayout.tsx
+++ b/apps/studio/components/layouts/EdgeFunctionsLayout/EdgeFunctionsLayout.tsx
@@ -4,7 +4,7 @@ import { PropsWithChildren } from 'react'
import { useParams } from 'common'
import { ProductMenu } from 'components/ui/ProductMenu'
import { withAuth } from 'hooks/misc/withAuth'
-import ProjectLayout from '../ProjectLayout/ProjectLayout'
+import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
const EdgeFunctionsProductMenu = () => {
const { ref: projectRef = 'default' } = useParams()
diff --git a/apps/studio/components/layouts/Integrations/layout.tsx b/apps/studio/components/layouts/Integrations/layout.tsx
index 87732d1a80d..dc944479462 100644
--- a/apps/studio/components/layouts/Integrations/layout.tsx
+++ b/apps/studio/components/layouts/Integrations/layout.tsx
@@ -2,7 +2,7 @@ import { useRouter } from 'next/router'
import { PropsWithChildren } from 'react'
import { useInstalledIntegrations } from 'components/interfaces/Integrations/Landing/useInstalledIntegrations'
-import ProjectLayout from 'components/layouts/ProjectLayout/ProjectLayout'
+import { ProjectLayout } from 'components/layouts/ProjectLayout/ProjectLayout'
import AlertError from 'components/ui/AlertError'
import { ProductMenu } from 'components/ui/ProductMenu'
import { ProductMenuGroup } from 'components/ui/ProductMenu/ProductMenu.types'
diff --git a/apps/studio/components/layouts/LogsLayout/LogsLayout.tsx b/apps/studio/components/layouts/LogsLayout/LogsLayout.tsx
index 9965ed65b2a..cba2574d6fa 100644
--- a/apps/studio/components/layouts/LogsLayout/LogsLayout.tsx
+++ b/apps/studio/components/layouts/LogsLayout/LogsLayout.tsx
@@ -5,7 +5,7 @@ import { PropsWithChildren } from 'react'
import NoPermission from 'components/ui/NoPermission'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { withAuth } from 'hooks/misc/withAuth'
-import ProjectLayout from '../ProjectLayout/ProjectLayout'
+import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
import { LogsSidebarMenuV2 } from './LogsSidebarMenuV2'
interface LogsLayoutProps {
diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx
index 004c7343fc5..e42923f075d 100644
--- a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx
@@ -3,7 +3,7 @@ import { ChevronLeft } from 'lucide-react'
import Link from 'next/link'
import { ReactNode, useMemo, useState } from 'react'
-import { useParams } from 'common'
+import { LOCAL_STORAGE_KEYS, useParams } from 'common'
import { useIsBranching2Enabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { Connect } from 'components/interfaces/Connect/Connect'
import { LocalDropdown } from 'components/interfaces/LocalDropdown'
@@ -16,6 +16,7 @@ import { ProjectDropdown } from 'components/layouts/AppLayout/ProjectDropdown'
import EditorPanel from 'components/ui/EditorPanel/EditorPanel'
import { getResourcesExceededLimitsOrg } from 'components/ui/OveragesBanner/OveragesBanner.utils'
import { useOrgUsageQuery } from 'data/usage/org-usage-query'
+import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { useHotKey } from 'hooks/ui/useHotKey'
@@ -74,12 +75,19 @@ const LayoutHeader = ({
const isAccountPage = router.pathname.startsWith('/account')
const [showEditorPanel, setShowEditorPanel] = useState(false)
+
+ const [inlineEditorHotkeyEnabled] = useLocalStorageQuery<boolean>(
+ LOCAL_STORAGE_KEYS.HOTKEY_INLINE_EDITOR,
+ true
+ )
+
useHotKey(
() => {
if (projectRef) setShowEditorPanel(!showEditorPanel)
},
'e',
- [showEditorPanel, projectRef]
+ [showEditorPanel, projectRef],
+ { enabled: inlineEditorHotkeyEnabled }
)
// We only want to query the org usage and check for possible over-ages for plans without usage billing enabled (free or pro with spend cap)
@@ -225,7 +233,10 @@ const LayoutHeader = ({
<AnimatePresence initial={false}>
{!!projectRef && (
<>
- <InlineEditorButton onClick={() => setShowEditorPanel(true)} />
+ <InlineEditorButton
+ onClick={() => setShowEditorPanel(true)}
+ showShortcut={inlineEditorHotkeyEnabled}
+ />
<AssistantButton />
</>
)}
@@ -240,7 +251,10 @@ const LayoutHeader = ({
<AnimatePresence initial={false}>
{!!projectRef && (
<>
- <InlineEditorButton onClick={() => setShowEditorPanel(true)} />
+ <InlineEditorButton
+ onClick={() => setShowEditorPanel(true)}
+ showShortcut={inlineEditorHotkeyEnabled}
+ />
<AssistantButton />
</>
)}
@@ -252,7 +266,11 @@ const LayoutHeader = ({
</div>
</div>
</header>
- <EditorPanel open={showEditorPanel} onClose={() => setShowEditorPanel(false)} />
+ <EditorPanel
+ open={showEditorPanel}
+ onClose={() => setShowEditorPanel(false)}
+ isInlineEditorHotkeyEnabled={inlineEditorHotkeyEnabled}
+ />
</>
)
}
diff --git a/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
index 02654ef391b..8752cde1a01 100644
--- a/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
@@ -3,13 +3,14 @@ import Head from 'next/head'
import { useRouter } from 'next/router'
import { forwardRef, Fragment, PropsWithChildren, ReactNode, useEffect, useState } from 'react'
-import { useParams } from 'common'
+import { LOCAL_STORAGE_KEYS, useParams } from 'common'
import { CreateBranchModal } from 'components/interfaces/BranchManagement/CreateBranchModal'
import ProjectAPIDocs from 'components/interfaces/ProjectAPIDocs/ProjectAPIDocs'
import { AIAssistant } from 'components/ui/AIAssistantPanel/AIAssistant'
import { Loading } from 'components/ui/Loading'
import { ResourceExhaustionWarningBanner } from 'components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner'
import { useCustomContent } from 'hooks/custom-content/useCustomContent'
+import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { withAuth } from 'hooks/misc/withAuth'
@@ -71,7 +72,7 @@ export interface ProjectLayoutProps {
productMenuClassName?: string
}
-const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<ProjectLayoutProps>>(
+export const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<ProjectLayoutProps>>(
(
{
title,
@@ -91,14 +92,19 @@ const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<ProjectLayout
const [isClient, setIsClient] = useState(false)
const { data: selectedOrganization } = useSelectedOrganizationQuery()
const { data: selectedProject } = useSelectedProjectQuery()
-
const { mobileMenuOpen, showSidebar, setMobileMenuOpen } = useAppStateSnapshot()
const aiSnap = useAiAssistantStateSnapshot()
+ const [isAiAssistantHotkeyEnabled] = useLocalStorageQuery<boolean>(
+ LOCAL_STORAGE_KEYS.HOTKEY_AI_ASSISTANT,
+ true
+ )
const { appTitle } = useCustomContent(['app:title'])
const titleSuffix = appTitle || 'Supabase'
- useHotKey(() => aiSnap.toggleAssistant(), 'i', [aiSnap])
+ useHotKey(() => aiSnap.toggleAssistant(), 'i', [aiSnap], {
+ enabled: isAiAssistantHotkeyEnabled,
+ })
const editor = useEditorType()
const forceShowProductMenu = editor === undefined
@@ -262,8 +268,6 @@ ProjectLayout.displayName = 'ProjectLayout'
export const ProjectLayoutWithAuth = withAuth(ProjectLayout)
-export default ProjectLayout
-
interface MenuBarWrapperProps {
isLoading: boolean
isBlocking?: boolean
diff --git a/apps/studio/components/layouts/ProjectSettingsLayout/SettingsLayout.tsx b/apps/studio/components/layouts/ProjectSettingsLayout/SettingsLayout.tsx
index 52123de65e1..5dbb91b642c 100644
--- a/apps/studio/components/layouts/ProjectSettingsLayout/SettingsLayout.tsx
+++ b/apps/studio/components/layouts/ProjectSettingsLayout/SettingsLayout.tsx
@@ -8,7 +8,7 @@ import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { withAuth } from 'hooks/misc/withAuth'
import { IS_PLATFORM } from 'lib/constants'
-import ProjectLayout from '../ProjectLayout/ProjectLayout'
+import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
import { generateSettingsMenu } from './SettingsMenu.utils'
interface SettingsLayoutProps {
diff --git a/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx b/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx
index 004a528e6b4..9c56dc29e0d 100644
--- a/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx
+++ b/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx
@@ -4,7 +4,7 @@ import { PropsWithChildren } from 'react'
import { ProductMenu } from 'components/ui/ProductMenu'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { withAuth } from 'hooks/misc/withAuth'
-import ProjectLayout from '../ProjectLayout/ProjectLayout'
+import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
import { generateRealtimeMenu } from './RealtimeMenu.utils'
export interface RealtimeLayoutProps {
diff --git a/apps/studio/components/layouts/ReportsLayout/ReportsLayout.tsx b/apps/studio/components/layouts/ReportsLayout/ReportsLayout.tsx
index 36bcf2cceeb..a5d5e33c7c3 100644
--- a/apps/studio/components/layouts/ReportsLayout/ReportsLayout.tsx
+++ b/apps/studio/components/layouts/ReportsLayout/ReportsLayout.tsx
@@ -4,7 +4,7 @@ import { useParams } from 'common'
import { UnknownInterface } from 'components/ui/UnknownInterface'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { withAuth } from 'hooks/misc/withAuth'
-import ProjectLayout from '../ProjectLayout/ProjectLayout'
+import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
import ReportsMenu from './ReportsMenu'
interface ReportsLayoutProps {
diff --git a/apps/studio/components/layouts/StorageLayout/StorageLayout.tsx b/apps/studio/components/layouts/StorageLayout/StorageLayout.tsx
index 17c85bcc69a..10057b90760 100644
--- a/apps/studio/components/layouts/StorageLayout/StorageLayout.tsx
+++ b/apps/studio/components/layouts/StorageLayout/StorageLayout.tsx
@@ -7,7 +7,7 @@ import { useSelectedBucket } from 'components/interfaces/Storage/StorageExplorer
import { StorageMenu } from 'components/interfaces/Storage/StorageMenu'
import { StorageMenuV2 } from 'components/interfaces/Storage/StorageMenuV2'
import { withAuth } from 'hooks/misc/withAuth'
-import ProjectLayout from '../ProjectLayout/ProjectLayout'
+import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
export interface StorageLayoutProps {
title: string
diff --git a/apps/studio/components/ui/AIEditor/index.tsx b/apps/studio/components/ui/AIEditor/index.tsx
index 3eccb949222..faf29dccb14 100644
--- a/apps/studio/components/ui/AIEditor/index.tsx
+++ b/apps/studio/components/ui/AIEditor/index.tsx
@@ -27,6 +27,7 @@ interface AIEditorProps {
options?: monacoEditor.IStandaloneEditorConstructionOptions
onChange?: (value: string) => void
onClose?: () => void
+ closeShortcutEnabled?: boolean
executeQuery?: () => void
}
@@ -47,11 +48,14 @@ const AIEditor = ({
options = {},
onChange,
onClose,
+ closeShortcutEnabled = true,
executeQuery,
}: AIEditorProps) => {
const os = detectOS()
const editorRef = useRef<monacoEditor.IStandaloneCodeEditor | null>(null)
const diffEditorRef = useRef<monacoEditor.IStandaloneDiffEditor | null>(null)
+ const monacoRef = useRef<Monaco | null>(null)
+ const closeActionDisposableRef = useRef<{ dispose: () => void } | null>(null)
const executeQueryRef = useRef(executeQuery)
executeQueryRef.current = executeQuery
@@ -142,11 +146,33 @@ const AIEditor = ({
handleReset()
}
+ const refreshCloseAction = useCallback(() => {
+ closeActionDisposableRef.current?.dispose()
+ closeActionDisposableRef.current = null
+
+ const editor = editorRef.current
+ const monaco = monacoRef.current
+
+ if (!editor || !monaco || !onClose || !closeShortcutEnabled) return
+
+ const action = editor.addAction({
+ id: 'close-editor',
+ label: 'Close editor',
+ keybindings: [monaco.KeyMod.CtrlCmd + monaco.KeyCode.KeyE],
+ contextMenuGroupId: 'operation',
+ contextMenuOrder: 0,
+ run: onClose,
+ })
+
+ closeActionDisposableRef.current = action ?? null
+ }, [closeShortcutEnabled, onClose])
+
const handleEditorOnMount: OnMount = (
editor: monacoEditor.IStandaloneCodeEditor,
monaco: Monaco
) => {
editorRef.current = editor
+ monacoRef.current = monaco
// Set prompt state to open if promptInput exists
if (promptInput) {
const model = editor.getModel()
@@ -193,16 +219,7 @@ const AIEditor = ({
})
}
- if (!!onClose) {
- editor.addAction({
- id: 'close-editor',
- label: 'Close editor',
- keybindings: [monaco.KeyMod.CtrlCmd + monaco.KeyCode.KeyE],
- contextMenuGroupId: 'operation',
- contextMenuOrder: 0,
- run: () => onClose(),
- })
- }
+ refreshCloseAction()
editor.addAction({
id: 'generate-ai',
diff --git a/apps/studio/components/ui/EditorPanel/EditorPanel.tsx b/apps/studio/components/ui/EditorPanel/EditorPanel.tsx
index 7dfa1aafbc0..d189ee02f7c 100644
--- a/apps/studio/components/ui/EditorPanel/EditorPanel.tsx
+++ b/apps/studio/components/ui/EditorPanel/EditorPanel.tsx
@@ -72,11 +72,13 @@ interface EditorPanelProps {
templates?: Template[]
initialPrompt?: string
onChange?: (value: string) => void
+ isInlineEditorHotkeyEnabled?: boolean
}
export const EditorPanel = ({
open,
onClose,
+ isInlineEditorHotkeyEnabled = true,
initialValue = '',
label = '',
saveLabel = 'Save',
@@ -312,7 +314,7 @@ export const EditorPanel = ({
text: (
<div className="flex items-center gap-4">
<span>Close Editor</span>
- <KeyboardShortcut keys={['Meta', 'e']} />
+ {isInlineEditorHotkeyEnabled && <KeyboardShortcut keys={['Meta', 'e']} />}
</div>
),
},
@@ -347,6 +349,7 @@ export const EditorPanel = ({
}}
executeQuery={onExecuteSql}
onClose={() => onClose()}
+ closeShortcutEnabled={isInlineEditorHotkeyEnabled}
/>
</div>
diff --git a/apps/studio/hooks/ui/useHotKey.ts b/apps/studio/hooks/ui/useHotKey.ts
index 4d1093ea10e..d8daff563c3 100644
--- a/apps/studio/hooks/ui/useHotKey.ts
+++ b/apps/studio/hooks/ui/useHotKey.ts
@@ -3,9 +3,14 @@ import { useEffect } from 'react'
export function useHotKey(
callback: (e: KeyboardEvent) => void,
key: string,
- dependencies: any[] = []
+ dependencies: any[] = [],
+ options?: { enabled?: boolean }
): void {
+ const enabled = options?.enabled ?? true
+
useEffect(() => {
+ if (!enabled) return
+
function handler(e: KeyboardEvent) {
if ((e.metaKey || e.ctrlKey) && e.key === key && !e.altKey && !e.shiftKey) {
callback(e)
@@ -16,5 +21,5 @@ export function useHotKey(
return () => {
window.removeEventListener('keydown', handler)
}
- }, [key, ...dependencies])
+ }, [key, enabled, ...dependencies])
}
diff --git a/apps/studio/pages/_app.tsx b/apps/studio/pages/_app.tsx
index 7eea0ec1d04..04aac87207a 100644
--- a/apps/studio/pages/_app.tsx
+++ b/apps/studio/pages/_app.tsx
@@ -30,12 +30,13 @@ import timezone from 'dayjs/plugin/timezone'
import utc from 'dayjs/plugin/utc'
import Head from 'next/head'
import { NuqsAdapter } from 'nuqs/adapters/next/pages'
-import { ErrorInfo, useCallback } from 'react'
+import { ErrorInfo, PropsWithChildren, useCallback } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import {
FeatureFlagProvider,
getFlags,
+ LOCAL_STORAGE_KEYS,
TelemetryTagManager,
ThemeProvider,
useThemeSandbox,
@@ -51,6 +52,7 @@ import { GlobalErrorBoundaryState } from 'components/ui/GlobalErrorBoundaryState
import { useRootQueryClient } from 'data/query-client'
import { customFont, sourceCodePro } from 'fonts'
import { useCustomContent } from 'hooks/custom-content/useCustomContent'
+import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { AuthProvider } from 'lib/auth'
import { API_URL, BASE_PATH, IS_PLATFORM, useDefaultProvider } from 'lib/constants'
import { ProfileProvider } from 'lib/profile'
@@ -78,6 +80,15 @@ loader.config({
},
})
+const CommandProviderWithPreferences = ({ children }: PropsWithChildren) => {
+ const [commandMenuHotkeyEnabled] = useLocalStorageQuery<boolean>(
+ LOCAL_STORAGE_KEYS.HOTKEY_COMMAND_MENU,
+ true
+ )
+
+ return <CommandProvider openKey={commandMenuHotkeyEnabled ? 'k' : ''}>{children}</CommandProvider>
+}
+
// [Joshen TODO] Once we settle on the new nav layout - we'll need a lot of clean up in terms of our layout components
// a lot of them are unnecessary and introduce way too many cluttered CSS especially with the height styles that make
// debugging way too difficult. Ideal scenario is we just have one AppLayout to control the height and scroll areas of
@@ -149,7 +160,7 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {
disableTransitionOnChange
>
<AppBannerContextProvider>
- <CommandProvider>
+ <CommandProviderWithPreferences>
<FeaturePreviewContextProvider>
{getLayout(<Component {...pageProps} />)}
<StudioCommandMenu />
@@ -157,7 +168,7 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {
</FeaturePreviewContextProvider>
<SonnerToaster position="top-right" />
<MonacoThemeProvider />
- </CommandProvider>
+ </CommandProviderWithPreferences>
</AppBannerContextProvider>
</ThemeProvider>
</RouteValidationWrapper>
diff --git a/apps/studio/pages/account/me.tsx b/apps/studio/pages/account/me.tsx
index 105f1ea0f9c..7f84e1127f7 100644
--- a/apps/studio/pages/account/me.tsx
+++ b/apps/studio/pages/account/me.tsx
@@ -4,6 +4,7 @@ import { AccountIdentities } from 'components/interfaces/Account/Preferences/Acc
import { AnalyticsSettings } from 'components/interfaces/Account/Preferences/AnalyticsSettings'
import { ProfileInformation } from 'components/interfaces/Account/Preferences/ProfileInformation'
import { ThemeSettings } from 'components/interfaces/Account/Preferences/ThemeSettings'
+import { HotkeySettings } from 'components/interfaces/Account/Preferences/HotkeySettings'
import AccountLayout from 'components/layouts/AccountLayout/AccountLayout'
import AppLayout from 'components/layouts/AppLayout/AppLayout'
import DefaultLayout from 'components/layouts/DefaultLayout'
@@ -83,6 +84,10 @@ const ProfileCard = () => {
<ThemeSettings />
</section>
+ <section>
+ <HotkeySettings />
+ </section>
+
{profileShowAnalyticsAndMarketing && (
<section>
<AnalyticsSettings />
diff --git a/apps/studio/pages/project/[ref]/logs/index.tsx b/apps/studio/pages/project/[ref]/logs/index.tsx
index 2c04272a4c1..b434b15c397 100644
--- a/apps/studio/pages/project/[ref]/logs/index.tsx
+++ b/apps/studio/pages/project/[ref]/logs/index.tsx
@@ -5,7 +5,7 @@ import { useParams } from 'common'
import { useUnifiedLogsPreview } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { UnifiedLogs } from 'components/interfaces/UnifiedLogs/UnifiedLogs'
import DefaultLayout from 'components/layouts/DefaultLayout'
-import ProjectLayout from 'components/layouts/ProjectLayout/ProjectLayout'
+import { ProjectLayout } from 'components/layouts/ProjectLayout/ProjectLayout'
import { NextPageWithLayout } from 'types'
export const LogPage: NextPageWithLayout = () => {
diff --git a/packages/common/constants/local-storage.ts b/packages/common/constants/local-storage.ts
index 4a3b4673d70..16cfe1f60c3 100644
--- a/packages/common/constants/local-storage.ts
+++ b/packages/common/constants/local-storage.ts
@@ -72,6 +72,10 @@ export const LOCAL_STORAGE_KEYS = {
USER_IMPERSONATION_SELECTOR_PREVIOUS_SEARCHES: (ref: string) =>
`user-impersonation-selector-previous-searches-${ref}`,
+ HOTKEY_INLINE_EDITOR: 'supabase-dashboard-hotkey-inline-editor',
+ HOTKEY_COMMAND_MENU: 'supabase-dashboard-hotkey-command-menu',
+ HOTKEY_AI_ASSISTANT: 'supabase-dashboard-hotkey-ai-assistant',
+
/**
* COMMON
*/
diff --git a/packages/ui-patterns/src/CommandMenu/api/CommandProvider.tsx b/packages/ui-patterns/src/CommandMenu/api/CommandProvider.tsx
index 6eb8fc5bf02..8cb7079a737 100644
--- a/packages/ui-patterns/src/CommandMenu/api/CommandProvider.tsx
+++ b/packages/ui-patterns/src/CommandMenu/api/CommandProvider.tsx
@@ -29,10 +29,12 @@ const CommandShortcut = ({ openKey }: { openKey: string }) => {
const toggleOpen = useToggleCommandMenu()
useEffect(() => {
- const handleKeydown = (evt: KeyboardEvent) => {
- if (openKey === '') return
+ if (openKey === '') return
- if (evt.key === openKey && evt.metaKey) {
+ const handleKeydown = (evt: KeyboardEvent) => {
+ const usesPrimaryModifier = evt.metaKey || evt.ctrlKey
+ const otherModifiersActive = evt.altKey || evt.shiftKey
+ if (evt.key === openKey && usesPrimaryModifier && !otherModifiersActive) {
evt.preventDefault()
toggleOpen()
}
@@ -41,7 +43,7 @@ const CommandShortcut = ({ openKey }: { openKey: string }) => {
document.addEventListener('keydown', handleKeydown)
return () => document.removeEventListener('keydown', handleKeydown)
- }, [toggleOpen])
+ }, [openKey, toggleOpen])
return null
}
diff --git a/packages/ui/src/components/KeyboardShortcut/KeyboardShortcut.tsx b/packages/ui/src/components/KeyboardShortcut/KeyboardShortcut.tsx
index 6a7f37654f9..b6f54b57a33 100644
--- a/packages/ui/src/components/KeyboardShortcut/KeyboardShortcut.tsx
+++ b/packages/ui/src/components/KeyboardShortcut/KeyboardShortcut.tsx
@@ -1,3 +1,5 @@
+import { cn } from '../../lib/utils'
+
const getIsMac = () => {
if (typeof navigator === 'undefined') return false
@@ -20,7 +22,11 @@ export const KeyboardShortcut = ({ keys }: { keys: string[] }) => {
<div className="text-xs text-foreground-light flex items-center gap-[3px]">
{keysWithMetaAndShift.map((key) => (
<span
- className="px-1.5 py-0.5 rounded-sm border-b-2 flex items-center justify-center border border-foreground-lightest cursor-default"
+ className={cn(
+ ['⌘', 'Shift', 'Ctrl'].includes(key) ? 'px-1.5 py-0.5' : 'w-[23px] h-[23px]',
+ 'border border-b-2 border-foreground-lightest',
+ 'rounded-sm flex items-center justify-center cursor-default'
+ )}
key={key}
>
{key}