Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button - Use single loop to set button content #160933

Merged
merged 1 commit into from Sep 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/vs/base/browser/ui/button/button.ts
Expand Up @@ -198,21 +198,24 @@ export class Button extends Disposable implements IButton {
set label(value: string) {
this._element.classList.add('monaco-text-button');
if (this.options.supportIcons) {
// Remove empty segments
const segments = renderLabelWithIcons(value)
.filter(segment => {
return (typeof (segment) === 'string' && segment.trim() === '') ? false : true;
});

// Convert string segments to <span> nodes
const content = segments.map(segment => {
const content: HTMLSpanElement[] = [];
for (let segment of renderLabelWithIcons(value)) {
if (typeof (segment) === 'string') {
segment = segment.trim();

// Ignore empty segment
if (segment === '') {
continue;
}

// Convert string segments to <span> nodes
const node = document.createElement('span');
node.textContent = segment.trim();
return node;
node.textContent = segment;
content.push(node);
} else {
content.push(segment);
}
return segment;
});
}

reset(this._element, ...content);
} else {
Expand Down