From 0c3798ae26d5fa26d6b7464691d7cd7ea94f6121 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Tue, 4 Aug 2020 14:33:25 -0700 Subject: [PATCH] Fix error when clicking on empty dropdown (#11637) --- src/vs/base/browser/ui/selectBox/selectBoxCustom.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/vs/base/browser/ui/selectBox/selectBoxCustom.ts b/src/vs/base/browser/ui/selectBox/selectBoxCustom.ts index 4aeab6db37..65770c5aba 100644 --- a/src/vs/base/browser/ui/selectBox/selectBoxCustom.ts +++ b/src/vs/base/browser/ui/selectBox/selectBoxCustom.ts @@ -704,8 +704,8 @@ export class SelectBoxList extends Disposable implements ISelectBoxDelegate, ILi let elementWidth = 0; if (container) { - let longest = 0; - let longestLength = 0; + let longest = -1; + let longestLength = -1; this.options.forEach((option, index) => { const len = option.text.length + (!!option.decoratorRight ? option.decoratorRight.length : 0); @@ -715,8 +715,10 @@ export class SelectBoxList extends Disposable implements ISelectBoxDelegate, ILi } }); + if (longest >= 0) { + container.innerHTML = this.options[longest].text + (!!this.options[longest].decoratorRight ? (this.options[longest].decoratorRight + ' ') : ''); + } - container.innerHTML = this.options[longest].text + (!!this.options[longest].decoratorRight ? (this.options[longest].decoratorRight + ' ') : ''); elementWidth = dom.getTotalWidth(container); }