Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export type MonacoSQLEditorProps = {
changePosition?: monaco.Position | null,
changeRange?: monaco.IRange | null,
) => void;
/** Immediate editor value change callback for lightweight UI state. */
onContentChange?: (value: string) => void;
/** Cursor change callback. */
onCursorChange?: (editor: monaco.editor.IStandaloneCodeEditor) => void;
/** Mouse click callback. */
Expand Down Expand Up @@ -111,6 +113,7 @@ const MonacoSQLEditor = forwardRef<MonacoEditorRef, MonacoSQLEditorProps>(
id,
defaultValue,
onChange,
onContentChange,
onCursorChange,
onMouseClick,
onMount,
Expand Down Expand Up @@ -716,6 +719,8 @@ const MonacoSQLEditor = forwardRef<MonacoEditorRef, MonacoSQLEditorProps>(

// Handle content changes.
const didChangeModelContentDisposer = editor.onDidChangeModelContent((event) => {
onContentChange?.(editor.getValue());

const lastChange = event.changes[event.changes.length - 1];
if (
event.changes.length === 1 &&
Expand Down Expand Up @@ -788,6 +793,7 @@ const MonacoSQLEditor = forwardRef<MonacoEditorRef, MonacoSQLEditorProps>(
handleContextMenu,
handleCursorChange,
handleValueChange,
onContentChange,
updateContentDiffGutterMarkers,
scheduleContentDiffHintsRefresh,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export interface SQLEditorProps {
onContextMenu?: (e: monaco.editor.IEditorMouseEvent) => void;
/** Editor value change callback. */
onChange?: (value: string) => void;
/** Immediate editor value change callback for lightweight UI state. */
onContentChange?: (value: string) => void;

dbInfo: IBoundInfo;
active?: boolean;
Expand Down Expand Up @@ -132,6 +134,7 @@ const SQLEditor = forwardRef<SQLEditorRef, SQLEditorProps>(
dbInfo,
active,
onChange,
onContentChange,
onContextMenu,
className,
readOnly,
Expand Down Expand Up @@ -989,6 +992,7 @@ const SQLEditor = forwardRef<SQLEditorRef, SQLEditorProps>(
defaultValue={defaultValue}
onMount={handleEditorMount}
onChange={handleValueChange}
onContentChange={onContentChange}
onCursorChange={handleCursorChange}
onMouseClick={handleMouseClick}
onContextMenu={handleContextMenu}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ const SQLEditorWithOperation = forwardRef<ISQLEditorWithOperationRef, ISQLEditor
const [contextTableIdentifier, setContextTableIdentifier] = useState<EditorTableIdentifier | null>(null);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [hasEditorContent, setHasEditorContent] = useState<boolean>(!!defaultSQL?.trim());
const handleEditorContentChange = useCallback((value: string) => {
setHasEditorContent(!!value.trim());
}, []);
const [routineExecutionModal, setRoutineExecutionModal] = useState({
open: false,
title: '',
Expand Down Expand Up @@ -941,9 +944,7 @@ const SQLEditorWithOperation = forwardRef<ISQLEditorWithOperationRef, ISQLEditor
readOnly={isReadOnly}
action={handleAction}
enableContentDiffHints={enableContentDiffHints}
onChange={(value) => {
setHasEditorContent(!!value?.trim());
}}
onContentChange={handleEditorContentChange}
contextMenuInfo={contextMenuInfo}
onTableIdentifierContextChange={setContextTableIdentifier}
onContextMenu={isReadOnly ? undefined : handleContextMenu}
Expand Down
Loading