fix: add auto-closing brackets to DBML editor (#1018)

This commit is contained in:
Guy Ben-Aharon
2025-12-17 17:51:07 +02:00
committed by GitHub
parent fad5adc048
commit f140d0528f
2 changed files with 31 additions and 0 deletions

View File

@@ -40,6 +40,34 @@ export const setupDBMLLanguage = (monaco: Monaco) => {
const dataTypesNames = dataTypes.map((dt) => dt.name);
const datatypePattern = dataTypesNames.join('|');
// Language configuration for auto-closing brackets, comments, etc.
monaco.languages.setLanguageConfiguration('dbml', {
brackets: [
['{', '}'],
['[', ']'],
['(', ')'],
],
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: "'", close: "'", notIn: ['string'] },
{ open: '`', close: '`', notIn: ['string'] },
],
surroundingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"' },
{ open: "'", close: "'" },
{ open: '`', close: '`' },
],
comments: {
lineComment: '//',
},
});
monaco.languages.setMonarchTokensProvider('dbml', {
keywords: ['Table', 'Ref', 'Indexes', 'Note', 'Enum', 'enum'],
datatypes: dataTypesNames,

View File

@@ -429,6 +429,9 @@ export const TableDBML: React.FC<TableDBMLProps> = () => {
wordWrap: 'off',
mouseWheelZoom: false,
readOnly: !isEditMode,
autoClosingBrackets: 'always',
autoClosingQuotes: 'always',
autoSurround: 'languageDefined',
},
onChange: (value) => {
setEditedDbml(value ?? '');