Skip to content

Commit

Permalink
Fix occasional bad custom selectbox layout
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Sep 8, 2020
1 parent 76e45c2 commit 7248c9a
Showing 1 changed file with 8 additions and 30 deletions.
38 changes: 8 additions & 30 deletions src/vs/base/browser/ui/selectBox/selectBoxCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,42 +503,15 @@ export class SelectBoxList extends Disposable implements ISelectBoxDelegate, ILi

// Iterate over detailed descriptions, find max height
private measureMaxDetailsHeight(): number {

let maxDetailsPaneHeight = 0;
this.options.forEach((option, index) => {

this.selectionDetailsPane.innerText = '';

if (option.description) {
if (option.descriptionIsMarkdown) {
this.selectionDetailsPane.appendChild(this.renderDescriptionMarkdown(option.description));
} else {
this.selectionDetailsPane.innerText = option.description;
}
this.selectionDetailsPane.style.display = 'block';
} else {
this.selectionDetailsPane.style.display = 'none';
}
this.options.forEach((_option, index) => {
this.updateDetail(index);

if (this.selectionDetailsPane.offsetHeight > maxDetailsPaneHeight) {
maxDetailsPaneHeight = this.selectionDetailsPane.offsetHeight;
}
});

// Reset description to selected

this.selectionDetailsPane.innerText = '';
const description = this.options[this.selected].description || null;
const descriptionIsMarkdown = this.options[this.selected].descriptionIsMarkdown || null;

if (description) {
if (descriptionIsMarkdown) {
this.selectionDetailsPane.appendChild(this.renderDescriptionMarkdown(description));
} else {
this.selectionDetailsPane.innerText = description;
}
this.selectionDetailsPane.style.display = 'block';
}
return maxDetailsPaneHeight;
}

Expand Down Expand Up @@ -676,6 +649,8 @@ export class SelectBoxList extends Disposable implements ISelectBoxDelegate, ILi
this.selectDropDownContainer.style.height = (listHeight + verticalPadding) + 'px';
}

this.updateDetail(this.selected);

this.selectDropDownContainer.style.width = selectOptimalWidth;

// Maintain focus outline on parent select as well as list container - tabindex for focus
Expand Down Expand Up @@ -870,8 +845,11 @@ export class SelectBoxList extends Disposable implements ISelectBoxDelegate, ILi
return;
}

this.updateDetail(e.indexes[0]);
}

private updateDetail(selectedIndex: number): void {
this.selectionDetailsPane.innerText = '';
const selectedIndex = e.indexes[0];
const description = this.options[selectedIndex].description;
const descriptionIsMarkdown = this.options[selectedIndex].descriptionIsMarkdown;

Expand Down

0 comments on commit 7248c9a

Please sign in to comment.