Skip to content

Commit

Permalink
Fixes #132162 by adding \b to brackets that use letters. Uses same lo…
Browse files Browse the repository at this point in the history
…gic as existing bracket matching code.
  • Loading branch information
hediet committed Oct 27, 2021
1 parent eebf638 commit e9e861f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/vs/editor/common/model/bracketPairs/impl/brackets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class BracketTokens {
const keys = [...this.map.keys()];
keys.sort();
keys.reverse();
return keys.map(k => escapeRegExpCharacters(k)).join('|');
return keys.map(k => prepareBracketForRegExp(k)).join('|');
}
}

Expand All @@ -99,6 +99,13 @@ export class BracketTokens {
}
}

function prepareBracketForRegExp(str: string): string {
const escaped = escapeRegExpCharacters(str);
// This bracket pair uses letters like e.g. "begin" - "end" (see https://github.com/microsoft/vscode/issues/132162)
const needsWordBoundaries = (/^[\w ]+$/.test(str));
return (needsWordBoundaries ? `\\b${escaped}\\b` : escaped);
}

export class LanguageAgnosticBracketTokens {
private readonly languageIdToBracketTokens = new Map<string, BracketTokens>();

Expand Down

0 comments on commit e9e861f

Please sign in to comment.