Skip to content

Commit ea62f67

Browse files
authored
Improve preference renderer linking (eclipse-theia#14311)
1 parent c24504b commit ea62f67

File tree

5 files changed

+40
-16
lines changed

5 files changed

+40
-16
lines changed

packages/core/src/browser/core-preferences.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ export const corePreferenceSchema: PreferenceSchema = {
9898
nls.localizeByDefault('Menu is displayed at the top of the window and only hidden in full screen mode.'),
9999
nls.localizeByDefault('Menu is always visible at the top of the window even in full screen mode.'),
100100
nls.localizeByDefault('Menu is always hidden.'),
101-
nls.localizeByDefault('Menu is displayed as a compact button in the side bar. This value is ignored when {0} is {1}.', '`#window.titleBarStyle#`', '`native`')
101+
environment.electron.is()
102+
? nls.localizeByDefault('Menu is displayed as a compact button in the side bar. This value is ignored when {0} is {1}.', '`#window.titleBarStyle#`', '`native`')
103+
: nls.localizeByDefault('Menu is displayed as a compact button in the side bar.')
102104
],
103105
default: 'classic',
104106
scope: 'application',

packages/editor/src/browser/editor-generated-preference-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ export const editorGeneratedPreferenceProperties: PreferenceSchema['properties']
759759
nls.localizeByDefault("`cursorSurroundingLines` is enforced only when triggered via the keyboard or API."),
760760
nls.localizeByDefault("`cursorSurroundingLines` is enforced always.")
761761
],
762-
"markdownDescription": nls.localize("theia/editor/editor.cursorSurroundingLinesStyle", "Controls when `#cursorSurroundingLines#` should be enforced."),
762+
"markdownDescription": nls.localizeByDefault("Controls when `#editor.cursorSurroundingLines#` should be enforced."),
763763
"type": "string",
764764
"enum": [
765765
"default",

packages/preferences/src/browser/style/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@
234234
text-decoration: none;
235235
}
236236

237+
.theia-settings-container .command-link {
238+
color: var(--theia-textLink-foreground);
239+
}
240+
237241
.theia-settings-container .settings-section a:hover {
238242
text-decoration: underline;
239243
}

packages/preferences/src/browser/util/preference-tree-generator.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class PreferenceTreeGenerator {
3939
@inject(PreferenceLayoutProvider) protected readonly layoutProvider: PreferenceLayoutProvider;
4040

4141
protected _root: CompositeTreeNode;
42+
protected _idCache = new Map<string, string>();
4243

4344
protected readonly onSchemaChangedEmitter = new Emitter<CompositeTreeNode>();
4445
readonly onSchemaChanged = this.onSchemaChangedEmitter.event;
@@ -60,6 +61,7 @@ export class PreferenceTreeGenerator {
6061
}
6162

6263
generateTree(): CompositeTreeNode {
64+
this._idCache.clear();
6365
const preferencesSchema = this.schemaProvider.getCombinedSchema();
6466
const propertyNames = Object.keys(preferencesSchema.properties);
6567
const groups = new Map<string, Preference.CompositeTreeNode>();
@@ -121,22 +123,23 @@ export class PreferenceTreeGenerator {
121123

122124
protected createBuiltinLeafNode(name: string, property: PreferenceDataProperty, root: CompositeTreeNode, groups: Map<string, Preference.CompositeTreeNode>): void {
123125
const layoutItem = this.layoutProvider.getLayoutForPreference(name);
124-
const labels = layoutItem ? layoutItem.id.split('.') : name.split('.');
126+
const labels = (layoutItem?.id ?? name).split('.');
125127
const groupID = this.getGroupName(labels);
126128
const subgroupName = this.getSubgroupName(labels, groupID);
127129
const subgroupID = [groupID, subgroupName].join('.');
128130
const toplevelParent = this.getOrCreatePreferencesGroup({
129131
id: groupID,
130132
group: groupID,
131133
root,
132-
groups
134+
groups,
135+
label: this.generateName(groupID)
133136
});
134137
const immediateParent = subgroupName ? this.getOrCreatePreferencesGroup({
135138
id: subgroupID,
136139
group: groupID,
137140
root: toplevelParent,
138141
groups,
139-
label: layoutItem?.label
142+
label: layoutItem?.label ?? this.generateName(subgroupName)
140143
}) : undefined;
141144
this.createLeafNode(name, immediateParent || toplevelParent, property);
142145
}
@@ -177,9 +180,7 @@ export class PreferenceTreeGenerator {
177180
}
178181

179182
getNodeId(preferenceId: string): string {
180-
const expectedGroup = this.getGroupName(preferenceId.split('.'));
181-
const expectedId = `${expectedGroup}@${preferenceId}`;
182-
return expectedId;
183+
return this._idCache.get(preferenceId) ?? '';
183184
}
184185

185186
protected getGroupName(labels: string[]): string {
@@ -200,6 +201,10 @@ export class PreferenceTreeGenerator {
200201
}
201202
}
202203

204+
protected generateName(id: string): string {
205+
return id.substring(0, 1).toUpperCase() + id.substring(1);
206+
}
207+
203208
doHandleChangedSchema(): void {
204209
const newTree = this.generateTree();
205210
this.onSchemaChangedEmitter.fire(newTree);
@@ -226,6 +231,7 @@ export class PreferenceTreeGenerator {
226231
preference: { data },
227232
depth: Preference.TreeNode.isTopLevel(preferencesGroup) ? 1 : 2
228233
};
234+
this._idCache.set(property, newNode.id);
229235
CompositeTreeNode.addChild(preferencesGroup, newNode);
230236
return newNode;
231237
}

packages/preferences/src/browser/views/components/preference-markdown-renderer.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ import { inject, injectable } from '@theia/core/shared/inversify';
1818
import { PreferenceTreeModel } from '../../preference-tree-model';
1919
import { PreferenceTreeLabelProvider } from '../../util/preference-tree-label-provider';
2020
import * as markdownit from '@theia/core/shared/markdown-it';
21+
import { CommandRegistry } from '@theia/core';
2122

2223
@injectable()
2324
export class PreferenceMarkdownRenderer {
2425

25-
@inject(PreferenceTreeModel) protected readonly model: PreferenceTreeModel;
26-
@inject(PreferenceTreeLabelProvider) protected readonly labelProvider: PreferenceTreeLabelProvider;
26+
@inject(PreferenceTreeModel)
27+
protected readonly model: PreferenceTreeModel;
28+
@inject(PreferenceTreeLabelProvider)
29+
protected readonly labelProvider: PreferenceTreeLabelProvider;
30+
@inject(CommandRegistry)
31+
protected readonly commandRegistry: CommandRegistry;
2732

2833
protected _renderer?: markdownit;
2934

@@ -47,19 +52,26 @@ export class PreferenceMarkdownRenderer {
4752
engine.renderer.rules.code_inline = (tokens, idx, options, env, self) => {
4853
const token = tokens[idx];
4954
const content = token.content;
50-
if (content.startsWith('#') && content.endsWith('#')) {
51-
const preferenceId = content.substring(1, content.length - 1);
52-
const preferenceNode = this.model.getNodeFromPreferenceId(preferenceId);
55+
if (content.length > 2 && content.startsWith('#') && content.endsWith('#')) {
56+
const id = content.substring(1, content.length - 1);
57+
// First check whether there's a preference with the given ID
58+
const preferenceNode = this.model.getNodeFromPreferenceId(id);
5359
if (preferenceNode) {
5460
let name = this.labelProvider.getName(preferenceNode);
5561
const prefix = this.labelProvider.getPrefix(preferenceNode, true);
5662
if (prefix) {
5763
name = prefix + name;
5864
}
59-
return `<a title="${preferenceId}" href="preference:${preferenceId}">${name}</a>`;
60-
} else {
61-
console.warn(`Linked preference "${preferenceId}" not found.`);
65+
return `<a title="${id}" href="preference:${id}">${name}</a>`;
6266
}
67+
// If no preference was found, check whether there's a command with the given ID
68+
const command = this.commandRegistry.getCommand(id);
69+
if (command) {
70+
const name = `${command.category ? `${command.category}: ` : ''}${command.label}`;
71+
return `<span class="command-link" title="${id}">${name}</span>`;
72+
}
73+
// If nothing was found, print a warning
74+
console.warn(`Linked preference "${id}" not found.`);
6375
}
6476
return inlineCode ? inlineCode(tokens, idx, options, env, self) : '';
6577
};

0 commit comments

Comments
 (0)