Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/browser/ui/iconLabel/iconLabels.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as dom from '../../dom.js';
7
import { ThemeIcon } from '../../../common/themables.js';
8
9
const labelWithIconsRegex = new RegExp(`(\\\\)?\\$\\((${ThemeIcon.iconNameExpression}(?:${ThemeIcon.iconModifierExpression})?)\\)`, 'g');
10
export function renderLabelWithIcons(text: string): Array<HTMLSpanElement | string> {
11
const elements = new Array<HTMLSpanElement | string>();
12
let match: RegExpExecArray | null;
13
14
let textStart = 0, textStop = 0;
15
while ((match = labelWithIconsRegex.exec(text)) !== null) {
16
textStop = match.index || 0;
17
if (textStart < textStop) {
18
elements.push(text.substring(textStart, textStop));
19
}
20
textStart = (match.index || 0) + match[0].length;
21
22
const [, escaped, codicon] = match;
23
elements.push(escaped ? `$(${codicon})` : renderIcon({ id: codicon }));
24
}
25
26
if (textStart < text.length) {
27
elements.push(text.substring(textStart));
28
}
29
return elements;
30
}
31
32
export function renderIcon(icon: ThemeIcon): HTMLSpanElement {
33
const node = dom.$(`span`);
34
node.classList.add(...ThemeIcon.asClassNameArray(icon));
35
return node;
36
}
37
38