Skip to content

Commit 4c083fa

Browse files
Merge pull request #5 from EdwardR0507/fix/sql-editor
fix: Improve Monaco Editor keyboard shortcuts and autocomplete widget display
2 parents ee83eb6 + 335617a commit 4c083fa

2 files changed

Lines changed: 53 additions & 17 deletions

File tree

src/app/globals.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,21 @@
409409
.dark .dotted-grid {
410410
opacity: 0.2;
411411
}
412+
413+
/* Monaco Editor Suggestions Widget - Ensure it appears above other elements */
414+
.monaco-editor .suggest-widget {
415+
z-index: 10000 !important;
416+
}
417+
418+
.monaco-editor .suggest-widget .monaco-list {
419+
z-index: 10000 !important;
420+
}
421+
422+
/* Ensure Monaco Editor container doesn't clip suggestions */
423+
.monaco-editor {
424+
overflow: visible !important;
425+
}
426+
427+
.monaco-editor .overflow-guard {
428+
overflow: visible !important;
429+
}

src/components/exercises/sql-editor.tsx

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)