From f57e2760a194cbca54f18dce030f239a067818c8 Mon Sep 17 00:00:00 2001 From: Mark Sujew Date: Mon, 14 Oct 2024 15:44:07 +0200 Subject: [PATCH 1/3] Improve preference renderer linking --- packages/core/src/browser/core-preferences.ts | 4 ++- .../editor-generated-preference-schema.ts | 2 +- .../browser/util/preference-tree-generator.ts | 18 ++++++++---- .../preference-markdown-renderer.ts | 28 +++++++++++++------ 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/packages/core/src/browser/core-preferences.ts b/packages/core/src/browser/core-preferences.ts index c9827c5aaf490..de52b471ce528 100644 --- a/packages/core/src/browser/core-preferences.ts +++ b/packages/core/src/browser/core-preferences.ts @@ -98,7 +98,9 @@ export const corePreferenceSchema: PreferenceSchema = { nls.localizeByDefault('Menu is displayed at the top of the window and only hidden in full screen mode.'), nls.localizeByDefault('Menu is always visible at the top of the window even in full screen mode.'), nls.localizeByDefault('Menu is always hidden.'), - nls.localizeByDefault('Menu is displayed as a compact button in the side bar. This value is ignored when {0} is {1}.', '`#window.titleBarStyle#`', '`native`') + environment.electron.is() + ? nls.localizeByDefault('Menu is displayed as a compact button in the side bar. This value is ignored when {0} is {1}.', '`#window.titleBarStyle#`', '`native`') + : nls.localizeByDefault('Menu is displayed as a compact button in the side bar.') ], default: 'classic', scope: 'application', diff --git a/packages/editor/src/browser/editor-generated-preference-schema.ts b/packages/editor/src/browser/editor-generated-preference-schema.ts index b75a3502b27a7..63b69a675c424 100644 --- a/packages/editor/src/browser/editor-generated-preference-schema.ts +++ b/packages/editor/src/browser/editor-generated-preference-schema.ts @@ -759,7 +759,7 @@ export const editorGeneratedPreferenceProperties: PreferenceSchema['properties'] nls.localizeByDefault("`cursorSurroundingLines` is enforced only when triggered via the keyboard or API."), nls.localizeByDefault("`cursorSurroundingLines` is enforced always.") ], - "markdownDescription": nls.localize("theia/editor/editor.cursorSurroundingLinesStyle", "Controls when `#cursorSurroundingLines#` should be enforced."), + "markdownDescription": nls.localizeByDefault("Controls when `#editor.cursorSurroundingLines#` should be enforced."), "type": "string", "enum": [ "default", diff --git a/packages/preferences/src/browser/util/preference-tree-generator.ts b/packages/preferences/src/browser/util/preference-tree-generator.ts index bacd4035d8534..c1fbff465c027 100644 --- a/packages/preferences/src/browser/util/preference-tree-generator.ts +++ b/packages/preferences/src/browser/util/preference-tree-generator.ts @@ -39,6 +39,7 @@ export class PreferenceTreeGenerator { @inject(PreferenceLayoutProvider) protected readonly layoutProvider: PreferenceLayoutProvider; protected _root: CompositeTreeNode; + protected _idCache = new Map(); protected readonly onSchemaChangedEmitter = new Emitter(); readonly onSchemaChanged = this.onSchemaChangedEmitter.event; @@ -60,6 +61,7 @@ export class PreferenceTreeGenerator { } generateTree(): CompositeTreeNode { + this._idCache.clear(); const preferencesSchema = this.schemaProvider.getCombinedSchema(); const propertyNames = Object.keys(preferencesSchema.properties); const groups = new Map(); @@ -121,7 +123,7 @@ export class PreferenceTreeGenerator { protected createBuiltinLeafNode(name: string, property: PreferenceDataProperty, root: CompositeTreeNode, groups: Map): void { const layoutItem = this.layoutProvider.getLayoutForPreference(name); - const labels = layoutItem ? layoutItem.id.split('.') : name.split('.'); + const labels = (layoutItem?.id ?? name).split('.'); const groupID = this.getGroupName(labels); const subgroupName = this.getSubgroupName(labels, groupID); const subgroupID = [groupID, subgroupName].join('.'); @@ -129,14 +131,15 @@ export class PreferenceTreeGenerator { id: groupID, group: groupID, root, - groups + groups, + label: this.generateName(groupID) }); const immediateParent = subgroupName ? this.getOrCreatePreferencesGroup({ id: subgroupID, group: groupID, root: toplevelParent, groups, - label: layoutItem?.label + label: layoutItem?.label ?? this.generateName(subgroupName) }) : undefined; this.createLeafNode(name, immediateParent || toplevelParent, property); } @@ -177,9 +180,7 @@ export class PreferenceTreeGenerator { } getNodeId(preferenceId: string): string { - const expectedGroup = this.getGroupName(preferenceId.split('.')); - const expectedId = `${expectedGroup}@${preferenceId}`; - return expectedId; + return this._idCache.get(preferenceId) ?? ''; } protected getGroupName(labels: string[]): string { @@ -200,6 +201,10 @@ export class PreferenceTreeGenerator { } } + protected generateName(id: string): string { + return id.substring(0, 1).toUpperCase() + id.substring(1); + } + doHandleChangedSchema(): void { const newTree = this.generateTree(); this.onSchemaChangedEmitter.fire(newTree); @@ -226,6 +231,7 @@ export class PreferenceTreeGenerator { preference: { data }, depth: Preference.TreeNode.isTopLevel(preferencesGroup) ? 1 : 2 }; + this._idCache.set(property, newNode.id); CompositeTreeNode.addChild(preferencesGroup, newNode); return newNode; } diff --git a/packages/preferences/src/browser/views/components/preference-markdown-renderer.ts b/packages/preferences/src/browser/views/components/preference-markdown-renderer.ts index 231524e99a504..debed455924bf 100644 --- a/packages/preferences/src/browser/views/components/preference-markdown-renderer.ts +++ b/packages/preferences/src/browser/views/components/preference-markdown-renderer.ts @@ -18,12 +18,17 @@ import { inject, injectable } from '@theia/core/shared/inversify'; import { PreferenceTreeModel } from '../../preference-tree-model'; import { PreferenceTreeLabelProvider } from '../../util/preference-tree-label-provider'; import * as markdownit from '@theia/core/shared/markdown-it'; +import { CommandRegistry } from '@theia/core'; @injectable() export class PreferenceMarkdownRenderer { - @inject(PreferenceTreeModel) protected readonly model: PreferenceTreeModel; - @inject(PreferenceTreeLabelProvider) protected readonly labelProvider: PreferenceTreeLabelProvider; + @inject(PreferenceTreeModel) + protected readonly model: PreferenceTreeModel; + @inject(PreferenceTreeLabelProvider) + protected readonly labelProvider: PreferenceTreeLabelProvider; + @inject(CommandRegistry) + protected readonly commandRegistry: CommandRegistry; protected _renderer?: markdownit; @@ -47,19 +52,26 @@ export class PreferenceMarkdownRenderer { engine.renderer.rules.code_inline = (tokens, idx, options, env, self) => { const token = tokens[idx]; const content = token.content; - if (content.startsWith('#') && content.endsWith('#')) { - const preferenceId = content.substring(1, content.length - 1); - const preferenceNode = this.model.getNodeFromPreferenceId(preferenceId); + if (content.length > 2 && content.startsWith('#') && content.endsWith('#')) { + const id = content.substring(1, content.length - 1); + // First check whether there's a preference with the given ID + const preferenceNode = this.model.getNodeFromPreferenceId(id); if (preferenceNode) { let name = this.labelProvider.getName(preferenceNode); const prefix = this.labelProvider.getPrefix(preferenceNode, true); if (prefix) { name = prefix + name; } - return `${name}`; - } else { - console.warn(`Linked preference "${preferenceId}" not found.`); + return `${name}`; } + // If no preference was found, check whether there's a command with the given ID + const command = this.commandRegistry.getCommand(id); + if (command) { + const name = `${command.category ? `${command.category}: ` : ''}${command.label}`; + return `${name}`; + } + // If nothing was found, print a warning + console.warn(`Linked preference "${id}" not found.`); } return inlineCode ? inlineCode(tokens, idx, options, env, self) : ''; }; From 4073d4d34ff23f58d7ee4aefb66ca9cfc173a3c1 Mon Sep 17 00:00:00 2001 From: Mark Sujew Date: Wed, 30 Oct 2024 09:45:35 +0000 Subject: [PATCH 2/3] Disable command links --- packages/preferences/src/browser/style/index.css | 5 +++++ .../browser/views/components/preference-markdown-renderer.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/preferences/src/browser/style/index.css b/packages/preferences/src/browser/style/index.css index 7015ed071c7df..252c26ce0a7df 100644 --- a/packages/preferences/src/browser/style/index.css +++ b/packages/preferences/src/browser/style/index.css @@ -234,6 +234,11 @@ text-decoration: none; } +.theia-settings-container .disabled-link { + pointer-events: none; + cursor: default; +} + .theia-settings-container .settings-section a:hover { text-decoration: underline; } diff --git a/packages/preferences/src/browser/views/components/preference-markdown-renderer.ts b/packages/preferences/src/browser/views/components/preference-markdown-renderer.ts index debed455924bf..c38f321687ca1 100644 --- a/packages/preferences/src/browser/views/components/preference-markdown-renderer.ts +++ b/packages/preferences/src/browser/views/components/preference-markdown-renderer.ts @@ -68,7 +68,7 @@ export class PreferenceMarkdownRenderer { const command = this.commandRegistry.getCommand(id); if (command) { const name = `${command.category ? `${command.category}: ` : ''}${command.label}`; - return `${name}`; + return `${name}`; } // If nothing was found, print a warning console.warn(`Linked preference "${id}" not found.`); From 15d787e404549d81325f75b51142df3df16e76c1 Mon Sep 17 00:00:00 2001 From: Mark Sujew Date: Wed, 30 Oct 2024 11:03:29 +0000 Subject: [PATCH 3/3] Use `span` instead --- packages/preferences/src/browser/style/index.css | 5 ++--- .../browser/views/components/preference-markdown-renderer.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/preferences/src/browser/style/index.css b/packages/preferences/src/browser/style/index.css index 252c26ce0a7df..dd598700451c9 100644 --- a/packages/preferences/src/browser/style/index.css +++ b/packages/preferences/src/browser/style/index.css @@ -234,9 +234,8 @@ text-decoration: none; } -.theia-settings-container .disabled-link { - pointer-events: none; - cursor: default; +.theia-settings-container .command-link { + color: var(--theia-textLink-foreground); } .theia-settings-container .settings-section a:hover { diff --git a/packages/preferences/src/browser/views/components/preference-markdown-renderer.ts b/packages/preferences/src/browser/views/components/preference-markdown-renderer.ts index c38f321687ca1..3cea617cec0bd 100644 --- a/packages/preferences/src/browser/views/components/preference-markdown-renderer.ts +++ b/packages/preferences/src/browser/views/components/preference-markdown-renderer.ts @@ -68,7 +68,7 @@ export class PreferenceMarkdownRenderer { const command = this.commandRegistry.getCommand(id); if (command) { const name = `${command.category ? `${command.category}: ` : ''}${command.label}`; - return `${name}`; + return `${name}`; } // If nothing was found, print a warning console.warn(`Linked preference "${id}" not found.`);