diff --git a/src/components/Editor/CadenceEditor/index.tsx b/src/components/Editor/CadenceEditor/index.tsx index 0d022324..4df113c6 100644 --- a/src/components/Editor/CadenceEditor/index.tsx +++ b/src/components/Editor/CadenceEditor/index.tsx @@ -174,6 +174,9 @@ const CadenceEditor = (props: CadenceEditorProps) => { readOnly: project.active.type === EntityType.AccountStorage || isMobile(), domReadOnly: isMobile(), contextmenu: !isMobile(), + autoClosingBrackets: 'languageDefined', + autoClosingQuotes: 'languageDefined', + autoSurround: 'languageDefined', }); const [code] = project.getActiveCode(); diff --git a/src/util/cadence.ts b/src/util/cadence.ts index c26598ca..fcc200ab 100644 --- a/src/util/cadence.ts +++ b/src/util/cadence.ts @@ -13,6 +13,27 @@ export default function configureCadence() { aliases: ['CDC', 'cdc'], }); + // Configure brackets and auto-closing pairs for the Cadence language + monaco.languages.setLanguageConfiguration(CADENCE_LANGUAGE_ID, { + brackets: [ + ['{', '}'], + ['[', ']'], + ['(', ')'], + ], + autoClosingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '"', close: '"', notIn: ['string'] }, + ], + surroundingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '"', close: '"' }, + ], + }); + const languageDef: IMonarchLanguage & { keywords: string[]; typeKeywords: string[];