diff --git a/src/vs/editor/common/cursor/cursorTypeEditOperations.ts b/src/vs/editor/common/cursor/cursorTypeEditOperations.ts index d1290a3e651db..f63abde46a772 100644 --- a/src/vs/editor/common/cursor/cursorTypeEditOperations.ts +++ b/src/vs/editor/common/cursor/cursorTypeEditOperations.ts @@ -262,6 +262,23 @@ export class AutoClosingOpenCharTypeOperation { if (!pair.shouldAutoClose(scopedLineTokens, beforeColumn - scopedLineTokens.firstCharOffset)) { return null; } + // If the cursor is inside an embedded language region (e.g. LaTeX + // embedded inside a markdown `$...$` math block), honor the + // embedded language's auto-closing pair configuration. Without + // this, the outer language's pairs (e.g. markdown's `<>`) would + // leak into regions where they are not meaningful. + // See https://github.com/microsoft/vscode/issues/272922 and the + // parent issue https://github.com/microsoft/vscode/issues/133397. + if (scopedLineTokens.languageId !== config.languageId) { + const embeddedConfig = config.languageConfigurationService.getLanguageConfiguration(scopedLineTokens.languageId); + const embeddedCandidates = embeddedConfig.getAutoClosingPairs().autoClosingPairsOpenByEnd.get(ch); + const hasMatchingEmbeddedPair = embeddedCandidates + ? embeddedCandidates.some(c => c.open === pair.open && c.close === pair.close) + : false; + if (!hasMatchingEmbeddedPair) { + return null; + } + } // Typing for example a quote could either start a new string, in which case auto-closing is desirable // or it could end a previously started string, in which case auto-closing is not desirable // diff --git a/src/vs/editor/common/cursorCommon.ts b/src/vs/editor/common/cursorCommon.ts index 4b03cf57d26fc..782b96456fae3 100644 --- a/src/vs/editor/common/cursorCommon.ts +++ b/src/vs/editor/common/cursorCommon.ts @@ -84,6 +84,10 @@ export class CursorConfiguration { private readonly _languageId: string; private _electricChars: { [key: string]: boolean } | null; + public get languageId(): string { + return this._languageId; + } + public static shouldRecreate(e: ConfigurationChangedEvent): boolean { return ( e.hasChanged(EditorOption.layoutInfo)