@@ -273,6 +273,9 @@ export function SqlEditor({
273273 const [ showSignupPrompt , setShowSignupPrompt ] = useState ( false ) ;
274274 const [ isMac , setIsMac ] = useState ( false ) ;
275275
276+ const onExecuteRef = useRef ( onExecute ) ;
277+ const formatSQLRef = useRef < ( ) => void > ( ( ) => { } ) ;
278+
276279 useEffect ( ( ) => {
277280 setIsMac ( navigator . platform . toUpperCase ( ) . includes ( "MAC" ) ) ;
278281 } , [ ] ) ;
@@ -359,6 +362,19 @@ export function SqlEditor({
359362 ) => {
360363 editorRef . current = editor ;
361364
365+ // Ctrl+Enter to execute
366+ editor . addCommand ( monaco . KeyMod . CtrlCmd | monaco . KeyCode . Enter , ( ) => {
367+ onExecuteRef . current ( ) ;
368+ } ) ;
369+
370+ // Ctrl+Shift+F to format
371+ editor . addCommand (
372+ monaco . KeyMod . CtrlCmd | monaco . KeyMod . Shift | monaco . KeyCode . KeyF ,
373+ ( ) => {
374+ formatSQLRef . current ( ) ;
375+ }
376+ ) ;
377+
362378 monaco . languages . registerCompletionItemProvider ( "sql" , {
363379 provideCompletionItems : ( model , position ) => {
364380 const word = model . getWordUntilPosition ( position ) ;
@@ -437,22 +453,12 @@ export function SqlEditor({
437453 } , [ value , onChange ] ) ;
438454
439455 useEffect ( ( ) => {
440- const handleKeyDown = ( e : KeyboardEvent ) => {
441- // Ctrl+Enter (Windows/Linux) or Cmd+Enter (Mac) to execute
442- if ( e . key === "Enter" && ( e . ctrlKey || e . metaKey ) && ! e . shiftKey ) {
443- e . preventDefault ( ) ;
444- onExecute ( ) ;
445- }
446- // Ctrl+Shift+F or Cmd+Shift+F to format
447- if ( e . key === "f" && ( e . ctrlKey || e . metaKey ) && e . shiftKey ) {
448- e . preventDefault ( ) ;
449- formatSQL ( ) ;
450- }
451- } ;
456+ onExecuteRef . current = onExecute ;
457+ } , [ onExecute ] ) ;
452458
453- window . addEventListener ( "keydown" , handleKeyDown ) ;
454- return ( ) => window . removeEventListener ( "keydown" , handleKeyDown ) ;
455- } , [ onExecute , formatSQL ] ) ;
459+ useEffect ( ( ) => {
460+ formatSQLRef . current = formatSQL ;
461+ } , [ formatSQL ] ) ;
456462
457463 const showSavedState = isSaved || wasAlreadySolved ;
458464
@@ -486,7 +492,7 @@ export function SqlEditor({
486492 />
487493 < Card
488494 className = { cn (
489- "relative overflow-hidden transition-colors duration-300" ,
495+ "relative transition-colors duration-300" ,
490496 isValidated
491497 ? "border-emerald-500/30"
492498 : hasError
@@ -496,7 +502,7 @@ export function SqlEditor({
496502 >
497503 < CardContent className = "p-0" >
498504 { /* Responsive editor height: smaller on mobile, larger on desktop */ }
499- < div className = "h-[150px] sm:h-[200px] lg:h-[250px]" >
505+ < div className = "h-[150px] sm:h-[200px] lg:h-[250px] overflow-visible " >
500506 < Editor
501507 height = "100%"
502508 defaultLanguage = "sql"
@@ -518,7 +524,19 @@ export function SqlEditor({
518524 preview : true ,
519525 showMethods : true ,
520526 showFunctions : true ,
527+ showIcons : true ,
528+ showStatusBar : true ,
529+ showSnippets : true ,
530+ } ,
531+ quickSuggestions : {
532+ other : true ,
533+ comments : true ,
534+ strings : true ,
521535 } ,
536+ suggestOnTriggerCharacters : true ,
537+ acceptSuggestionOnCommitCharacter : true ,
538+ acceptSuggestionOnEnter : "on" ,
539+ snippetSuggestions : "top" ,
522540 } }
523541 onMount = { handleEditorDidMount }
524542 />
0 commit comments