未验证 提交 9752af2c 编写于 作者: A Alex Dima

Fixes #84595: editor.matchBrackets can now be 'never' | 'near' | 'always'

上级 e7c13723
......@@ -263,6 +263,13 @@ function migrateOptions(options: IEditorOptions): void {
} else if (<any>autoIndent === false) {
options.autoIndent = 'advanced';
}
const matchBrackets = options.matchBrackets;
if (<any>matchBrackets === true) {
options.matchBrackets = 'always';
} else if (<any>matchBrackets === false) {
options.matchBrackets = 'never';
}
}
function deepCloneAndMigrateOptions(_options: IEditorOptions): IEditorOptions {
......
......@@ -481,9 +481,9 @@ export interface IEditorOptions {
showFoldingControls?: 'always' | 'mouseover';
/**
* Enable highlighting of matching brackets.
* Defaults to true.
* Defaults to 'always'.
*/
matchBrackets?: boolean;
matchBrackets?: 'never' | 'near' | 'always';
/**
* Enable rendering of whitespace.
* Defaults to none.
......@@ -3356,9 +3356,11 @@ export const EditorOptions = {
EditorOption.links, 'links', true,
{ description: nls.localize('links', "Controls whether the editor should detect links and make them clickable.") }
)),
matchBrackets: register(new EditorBooleanOption(
EditorOption.matchBrackets, 'matchBrackets', true,
{ description: nls.localize('matchBrackets', "Highlight matching brackets when one of them is selected.") }
matchBrackets: register(new EditorStringEnumOption(
EditorOption.matchBrackets, 'matchBrackets',
'always' as 'never' | 'near' | 'always',
['always', 'near', 'never'] as const,
{ description: nls.localize('matchBrackets', "Highlight matching brackets.") }
)),
minimap: register(new EditorMinimap()),
mouseStyle: register(new EditorStringEnumOption(
......
......@@ -116,7 +116,7 @@ export class BracketMatchingController extends Disposable implements editorCommo
private _lastVersionId: number;
private _decorations: string[];
private readonly _updateBracketsSoon: RunOnceScheduler;
private _matchBrackets: boolean;
private _matchBrackets: 'never' | 'near' | 'always';
constructor(
editor: ICodeEditor
......@@ -132,7 +132,7 @@ export class BracketMatchingController extends Disposable implements editorCommo
this._updateBracketsSoon.schedule();
this._register(editor.onDidChangeCursorPosition((e) => {
if (!this._matchBrackets) {
if (this._matchBrackets === 'never') {
// Early exit if nothing needs to be done!
// Leave some form of early exit check here if you wish to continue being a cursor position change listener ;)
return;
......@@ -153,12 +153,13 @@ export class BracketMatchingController extends Disposable implements editorCommo
this._updateBracketsSoon.schedule();
}));
this._register(editor.onDidChangeConfiguration((e) => {
this._matchBrackets = this._editor.getOption(EditorOption.matchBrackets);
if (!this._matchBrackets && this._decorations.length > 0) {
// Remove existing decorations if bracket matching is off
if (e.hasChanged(EditorOption.matchBrackets)) {
this._matchBrackets = this._editor.getOption(EditorOption.matchBrackets);
this._decorations = this._editor.deltaDecorations(this._decorations, []);
this._lastBracketsData = [];
this._lastVersionId = 0;
this._updateBracketsSoon.schedule();
}
this._updateBracketsSoon.schedule();
}));
}
......@@ -262,7 +263,7 @@ export class BracketMatchingController extends Disposable implements editorCommo
});
private _updateBrackets(): void {
if (!this._matchBrackets) {
if (this._matchBrackets === 'never') {
return;
}
this._recomputeBrackets();
......@@ -332,7 +333,7 @@ export class BracketMatchingController extends Disposable implements editorCommo
} else {
let brackets = model.matchBracket(position);
let options = BracketMatchingController._DECORATION_OPTIONS_WITH_OVERVIEW_RULER;
if (!brackets) {
if (!brackets && this._matchBrackets === 'always') {
brackets = model.findEnclosingBrackets(position);
options = BracketMatchingController._DECORATION_OPTIONS_WITHOUT_OVERVIEW_RULER;
}
......
......@@ -2880,9 +2880,9 @@ declare namespace monaco.editor {
showFoldingControls?: 'always' | 'mouseover';
/**
* Enable highlighting of matching brackets.
* Defaults to true.
* Defaults to 'always'.
*/
matchBrackets?: boolean;
matchBrackets?: 'never' | 'near' | 'always';
/**
* Enable rendering of whitespace.
* Defaults to none.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册