The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(sql-editor): ai keyboard shortcuts
Greg Richardson7152bc866cf8
diff --git a/studio/components/interfaces/SQLEditor/AskAIWidget.tsx b/studio/components/interfaces/SQLEditor/AskAIWidget.tsxindex 7e5e357898c..ec885d9a11d 100644--- a/studio/components/interfaces/SQLEditor/AskAIWidget.tsx+++ b/studio/components/interfaces/SQLEditor/AskAIWidget.tsx@@ -1,10 +1,7 @@-import { detectOS } from 'lib/helpers'import { useCallback } from 'react'import { AiIcon, IconCornerDownLeft, Input } from 'ui'const AskAIWidget = () => {- const os = detectOS()-// Auto focus inputconst inputRef = useCallback((input: HTMLInputElement | null) => {setTimeout(() => {@@ -23,26 +20,7 @@ const AskAIWidget = () => {placeholder="Ask Supabase AI to do something"autoFocusactions={- <div className="flex items-center space-x-1 mr-6">- {os === 'macos' ? (- <svg- width="16"- height="16"- viewBox="0 0 24 24"- fill="none"- xmlns="http://www.w3.org/2000/svg"- >- <path- d="M3 5H7.76472L16.2353 19H21M16.2353 5H21"- stroke="currentColor"- strokeWidth="1.5"- strokeLinecap="square"- strokeLinejoin="round"- />- </svg>- ) : (- <p className="text-xs text-scale-1100">ALT</p>- )}+ <div className="flex items-center space-x-1 mr-4"><IconCornerDownLeft size={16} strokeWidth={1.5} /></div>}diff --git a/studio/components/interfaces/SQLEditor/MonacoEditor.tsx b/studio/components/interfaces/SQLEditor/MonacoEditor.tsxindex 29ff495937e..9a75b0d7b18 100644--- a/studio/components/interfaces/SQLEditor/MonacoEditor.tsx+++ b/studio/components/interfaces/SQLEditor/MonacoEditor.tsx@@ -1,7 +1,7 @@import Editor, { Monaco, OnMount } from '@monaco-editor/react'import { timeout } from 'lib/helpers'import { Selection, editor } from 'monaco-editor'-import { MutableRefObject, useRef, useState } from 'react'+import { MutableRefObject, useEffect, useRef, useState } from 'react'import { useSqlEditorStateSnapshot } from 'state/sql-editor'import AskAIWidget from './AskAIWidget'import InlineWidget from './InlineWidget'@@ -52,7 +52,7 @@ const MonacoEditor = ({ id, editorRef, isExecuting, executeQuery }: MonacoEditoreditor.addAction({id: 'ask-ai',label: 'Ask AI',- keybindings: [monaco.KeyMod.Alt + monaco.KeyCode.Enter],+ keybindings: [monaco.KeyMod.CtrlCmd + monaco.KeyCode.KeyI],contextMenuGroupId: 'operation',contextMenuOrder: 0,run: () => {@@ -79,6 +79,25 @@ const MonacoEditor = ({ id, editorRef, isExecuting, executeQuery }: MonacoEditoreditor.focus()}+ useEffect(() => {+ if (!isAiWidgetOpen) {+ return+ }++ function onKeyDown(e: KeyboardEvent) {+ if (e.key === 'Escape') {+ setIsAiWidgetOpen(false)+ editor?.focus()+ }+ }++ window.addEventListener('keydown', onKeyDown)++ return () => {+ window.removeEventListener('keydown', onKeyDown)+ }+ }, [editor, isAiWidgetOpen])+function handleEditorChange(value: string | undefined) {if (id && value) snap.setSql(id, value)}