Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(web-terminal): the Enter to execute feature should not prevent default behaviors when not needed. (#3620)
Liu Ji4e50bbed37c0
diff --git a/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue b/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vueindex e0a1b59097..a2fffd789b 100644--- a/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue+++ b/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue@@ -177,33 +177,57 @@ const handleEditorReady = async () => {},});- editor?.addCommand(monaco.KeyCode.Enter, (...args: any[]) => {- // When- // - the SQL ends with ";"- // - and the cursor is at the end of the editor- // - then press "Enter"- // We trigger the "execute" event- if (props.sql.endsWith(";")) {- const model = editor.getModel();- if (model) {- const maxLine = model.getLineCount();- const maxColumn = model.getLineMaxColumn(maxLine);- const cursor = editor.getPosition();- const isCursorAtLast = !!cursor?.equals({- lineNumber: maxLine,- column: maxColumn,- });- if (isCursorAtLast) {- emit("execute", props.sql, {- databaseType: selectedInstanceEngine.value,- });- return false;- }+ // Create an editor context value to check if the SQL ends with semicolon ";"+ const endsWithSemicolon = editor?.createContextKey<boolean>(+ "endsWithSemicolon",+ false+ );+ editor?.onDidChangeModelContent(() => {+ const value = editor.getValue();+ if (value.endsWith(";")) {+ endsWithSemicolon?.set(true);+ } else {+ endsWithSemicolon?.set(false);+ }+ });+ // Another editor context value to check if the cursor is at the end of the+ // editor.+ const cursorAtLast = editor?.createContextKey<boolean>("cursorAtLast", false);+ editor?.onDidChangeCursorPosition(() => {+ const model = editor.getModel();+ if (model) {+ const maxLine = model.getLineCount();+ const maxColumn = model.getLineMaxColumn(maxLine);+ const cursor = editor.getPosition();+ const isCursorAtLast = !!cursor?.equals({+ lineNumber: maxLine,+ column: maxColumn,+ });+ if (isCursorAtLast) {+ cursorAtLast?.set(true);+ return;}}- return true;+ cursorAtLast?.set(false);});+ editor?.addCommand(+ monaco.KeyCode.Enter,+ () => {+ // When+ // - the SQL ends with ";"+ // - and the cursor is at the end of the editor+ // - then press "Enter"+ // We trigger the "execute" event+ emit("execute", props.sql, {+ databaseType: selectedInstanceEngine.value,+ });+ },+ // Tell the editor this should be only+ // triggered when both of the two conditions are satisfied.+ "endsWithSemicolon && cursorAtLast"+ );+watchEffect(() => {if (selectedInstance.value) {const databaseList = databaseStore.getDatabaseListByInstanceId(