Skip to content

Commit

Permalink
feat: render keybinding label for chat /help command link (microsof…
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl committed Dec 2, 2023
1 parent 8a3a7a7 commit 4fc3ed3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/vs/workbench/contrib/chat/browser/chatListRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { FileKind } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { WorkbenchCompressibleAsyncDataTree, WorkbenchList } from 'vs/platform/list/browser/listService';
import { ILogService } from 'vs/platform/log/common/log';
import { IOpenerService } from 'vs/platform/opener/common/opener';
Expand Down Expand Up @@ -140,6 +141,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
@IEditorService private readonly editorService: IEditorService,
@IProductService productService: IProductService,
@IThemeService private readonly themeService: IThemeService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
) {
super();
this.renderer = this.instantiationService.createInstance(MarkdownRenderer, {});
Expand Down Expand Up @@ -814,7 +816,18 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
const disposables = new DisposableStore();
let codeBlockIndex = 0;

markdown = new MarkdownString(markdown.value, {
// inject keybinding hints for command links
const value = markdown.value.replace(/\[([^\]]+)\]\(command:([^\)]+)\)/g, (match, label, command) => {
const keybinding = this.keybindingService.lookupKeybinding(command);
const keybindingLabel = keybinding?.getLabel();
if (keybindingLabel) {
// ideally we would use the keybindingLabel renderer but dompurify sanitizes the styling
return `${match} (\`${keybindingLabel}\`)`;
}
return match;
});

markdown = new MarkdownString(value, {
isTrusted: {
// Disable all other config options except isTrusted
enabledCommands: typeof markdown.isTrusted === 'object' ? markdown.isTrusted?.enabledCommands : [] ?? []
Expand Down

0 comments on commit 4fc3ed3

Please sign in to comment.