From a7d6660f48af287c897dcc27327f53148208dea9 Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Sun, 26 Apr 2020 22:01:16 -0500 Subject: [PATCH] Add markdownDeprecationMessage Fix bug with search + clicking setting name links Fix #91618 --- src/vs/base/common/jsonSchema.ts | 23 ++++++++++--------- .../preferences/browser/settingsEditor2.ts | 14 +++++------ .../preferences/browser/settingsTree.ts | 15 ++++++++---- .../preferences/browser/settingsWidgets.ts | 10 ++++---- .../preferences/common/preferences.ts | 1 + .../preferences/common/preferencesModels.ts | 3 ++- 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/vs/base/common/jsonSchema.ts b/src/vs/base/common/jsonSchema.ts index 3af5da703672d..1c6fea1f9c7b3 100644 --- a/src/vs/base/common/jsonSchema.ts +++ b/src/vs/base/common/jsonSchema.ts @@ -53,17 +53,18 @@ export interface IJSONSchema { then?: IJSONSchema; else?: IJSONSchema; - // VSCode extensions - defaultSnippets?: IJSONSchemaSnippet[]; // VSCode extension - errorMessage?: string; // VSCode extension - patternErrorMessage?: string; // VSCode extension - deprecationMessage?: string; // VSCode extension - enumDescriptions?: string[]; // VSCode extension - markdownEnumDescriptions?: string[]; // VSCode extension - markdownDescription?: string; // VSCode extension - doNotSuggest?: boolean; // VSCode extension - allowComments?: boolean; // VSCode extension - allowTrailingCommas?: boolean; // VSCode extension + // VS Code extensions + defaultSnippets?: IJSONSchemaSnippet[]; + errorMessage?: string; + patternErrorMessage?: string; + deprecationMessage?: string; + markdownDeprecationMessage?: string; + enumDescriptions?: string[]; + markdownEnumDescriptions?: string[]; + markdownDescription?: string; + doNotSuggest?: boolean; + allowComments?: boolean; + allowTrailingCommas?: boolean; } export interface IJSONSchemaMap { diff --git a/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts b/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts index 87b52a7d06dd0..ba98354fade78 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts @@ -493,14 +493,14 @@ export class SettingsEditor2 extends BaseEditor { private onDidClickSetting(evt: ISettingLinkClickEvent, recursed?: boolean): void { const elements = this.currentSettingsModel.getElementsByName(evt.targetKey); if (elements && elements[0]) { - let sourceTop = this.settingsTree.getRelativeTop(evt.source); - if (typeof sourceTop !== 'number') { - return; - } - - if (sourceTop < 0) { + let sourceTop = 0.5; + try { + const _sourceTop = this.settingsTree.getRelativeTop(evt.source); + if (_sourceTop !== null) { + sourceTop = _sourceTop; + } + } catch { // e.g. clicked a searched element, now the search has been cleared - sourceTop = 0.5; } this.settingsTree.reveal(elements[0], sourceTop); diff --git a/src/vs/workbench/contrib/preferences/browser/settingsTree.ts b/src/vs/workbench/contrib/preferences/browser/settingsTree.ts index d3fac7a16a764..21738f1e575fd 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsTree.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsTree.ts @@ -510,7 +510,14 @@ export abstract class AbstractSettingRenderer extends Disposable implements ITre const onChange = (value: any) => this._onDidChangeSetting.fire({ key: element.setting.key, value, type: template.context!.valueType }); const deprecationText = element.setting.deprecationMessage || ''; - template.deprecationWarningElement.innerText = deprecationText; + if (deprecationText && element.setting.deprecationMessageIsMarkdown) { + const disposables = new DisposableStore(); + template.elementDisposables.add(disposables); + template.deprecationWarningElement.innerHTML = ''; + template.deprecationWarningElement.appendChild(this.renderSettingMarkdown(element, element.setting.deprecationMessage!, template.elementDisposables)); + } else { + template.deprecationWarningElement.innerText = deprecationText; + } DOM.toggleClass(template.containerElement, 'is-deprecated', !!deprecationText); this.renderValue(element, template, onChange); @@ -524,7 +531,7 @@ export abstract class AbstractSettingRenderer extends Disposable implements ITre })); } - private renderDescriptionMarkdown(element: SettingsTreeSettingElement, text: string, disposeables: DisposableStore): HTMLElement { + private renderSettingMarkdown(element: SettingsTreeSettingElement, text: string, disposeables: DisposableStore): HTMLElement { // Rewrite `#editor.fontSize#` to link format text = fixSettingLinks(text); @@ -545,7 +552,7 @@ export abstract class AbstractSettingRenderer extends Disposable implements ITre } }); - renderedMarkdown.classList.add('setting-item-description-markdown'); + renderedMarkdown.classList.add('setting-item-markdown'); cleanRenderedMarkdown(renderedMarkdown); return renderedMarkdown; } @@ -615,7 +622,7 @@ export abstract class AbstractSettingRenderer extends Disposable implements ITre disposeElement(_element: ITreeNode, _index: number, template: IDisposableTemplate, _height: number | undefined): void { if ((template as ISettingItemTemplate).elementDisposables) { - dispose((template as ISettingItemTemplate).elementDisposables); + (template as ISettingItemTemplate).elementDisposables.clear(); } } } diff --git a/src/vs/workbench/contrib/preferences/browser/settingsWidgets.ts b/src/vs/workbench/contrib/preferences/browser/settingsWidgets.ts index 921a26078af0f..d17e608bb9024 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsWidgets.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsWidgets.ts @@ -69,16 +69,16 @@ registerThemingParticipant((theme: IColorTheme, collector: ICssStyleCollector) = const link = theme.getColor(textLinkForeground); if (link) { - collector.addRule(`.settings-editor > .settings-body > .settings-tree-container .setting-item-contents .setting-item-description-markdown a { color: ${link}; }`); - collector.addRule(`.settings-editor > .settings-body > .settings-tree-container .setting-item-contents .setting-item-description-markdown a > code { color: ${link}; }`); + collector.addRule(`.settings-editor > .settings-body > .settings-tree-container .setting-item-contents .setting-item-markdown a { color: ${link}; }`); + collector.addRule(`.settings-editor > .settings-body > .settings-tree-container .setting-item-contents .setting-item-markdown a > code { color: ${link}; }`); collector.addRule(`.monaco-select-box-dropdown-container > .select-box-details-pane > .select-box-description-markdown a { color: ${link}; }`); collector.addRule(`.monaco-select-box-dropdown-container > .select-box-details-pane > .select-box-description-markdown a > code { color: ${link}; }`); } const activeLink = theme.getColor(textLinkActiveForeground); if (activeLink) { - collector.addRule(`.settings-editor > .settings-body > .settings-tree-container .setting-item-contents .setting-item-description-markdown a:hover, .settings-editor > .settings-body > .settings-tree-container .setting-item-contents .setting-item-description-markdown a:active { color: ${activeLink}; }`); - collector.addRule(`.settings-editor > .settings-body > .settings-tree-container .setting-item-contents .setting-item-description-markdown a:hover > code, .settings-editor > .settings-body > .settings-tree-container .setting-item-contents .setting-item-description-markdown a:active > code { color: ${activeLink}; }`); + collector.addRule(`.settings-editor > .settings-body > .settings-tree-container .setting-item-contents .setting-item-markdown a:hover, .settings-editor > .settings-body > .settings-tree-container .setting-item-contents .setting-item-markdown a:active { color: ${activeLink}; }`); + collector.addRule(`.settings-editor > .settings-body > .settings-tree-container .setting-item-contents .setting-item-markdown a:hover > code, .settings-editor > .settings-body > .settings-tree-container .setting-item-contents .setting-item-markdown a:active > code { color: ${activeLink}; }`); collector.addRule(`.monaco-select-box-dropdown-container > .select-box-details-pane > .select-box-description-markdown a:hover, .monaco-select-box-dropdown-container > .select-box-details-pane > .select-box-description-markdown a:active { color: ${activeLink}; }`); collector.addRule(`.monaco-select-box-dropdown-container > .select-box-details-pane > .select-box-description-markdown a:hover > code, .monaco-select-box-dropdown-container > .select-box-details-pane > .select-box-description-markdown a:active > code { color: ${activeLink}; }`); } @@ -126,7 +126,7 @@ registerThemingParticipant((theme: IColorTheme, collector: ICssStyleCollector) = const codeTextForegroundColor = theme.getColor(textPreformatForeground); if (codeTextForegroundColor) { - collector.addRule(`.settings-editor > .settings-body > .settings-tree-container .setting-item .setting-item-description-markdown code { color: ${codeTextForegroundColor} }`); + collector.addRule(`.settings-editor > .settings-body > .settings-tree-container .setting-item .setting-item-markdown code { color: ${codeTextForegroundColor} }`); collector.addRule(`.monaco-select-box-dropdown-container > .select-box-details-pane > .select-box-description-markdown code { color: ${codeTextForegroundColor} }`); } diff --git a/src/vs/workbench/services/preferences/common/preferences.ts b/src/vs/workbench/services/preferences/common/preferences.ts index 093f10ecaa565..e39388c5e7114 100644 --- a/src/vs/workbench/services/preferences/common/preferences.ts +++ b/src/vs/workbench/services/preferences/common/preferences.ts @@ -59,6 +59,7 @@ export interface ISetting { overrides?: ISetting[]; overrideOf?: ISetting; deprecationMessage?: string; + deprecationMessageIsMarkdown?: boolean; scope?: ConfigurationScope; type?: string | string[]; diff --git a/src/vs/workbench/services/preferences/common/preferencesModels.ts b/src/vs/workbench/services/preferences/common/preferencesModels.ts index 93cfa52a02e09..c59948ab5d577 100644 --- a/src/vs/workbench/services/preferences/common/preferencesModels.ts +++ b/src/vs/workbench/services/preferences/common/preferencesModels.ts @@ -639,7 +639,8 @@ export class DefaultSettings extends Disposable { tags: prop.tags, disallowSyncIgnore: prop.disallowSyncIgnore, extensionInfo: extensionInfo, - deprecationMessage: prop.deprecationMessage, + deprecationMessage: prop.deprecationMessage || prop.markdownDeprecationMessage, + deprecationMessageIsMarkdown: !prop.deprecationMessage, validator: createValidator(prop) }); }