Skip to content

Commit 9f4d6cf

Browse files
committed
rename suggestions: fix overflowing candidate names - update list widget width
1 parent b341631 commit 9f4d6cf

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/vs/editor/contrib/rename/browser/renameInputField.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ export class RenameInputField implements IContentWidget {
202202
const [accept, preview] = this._acceptKeybindings;
203203
this._label!.innerText = localize({ key: 'label', comment: ['placeholders are keybindings, e.g "F2 to Rename, Shift+F2 to Preview"'] }, "{0} to Rename, {1} to Preview", this._keybindingService.lookupKeybinding(accept)?.getLabel(), this._keybindingService.lookupKeybinding(preview)?.getLabel());
204204

205-
this._domNode!.style.minWidth = `250px`; // to prevent from widening when candidates come in
206-
this._domNode!.style.maxWidth = `400px`; // TODO@ulugbekna: what if we have a very long name?
205+
this._domNode!.style.minWidth = `200px`; // to prevent from widening when candidates come in
207206

208207
return null;
209208
}
@@ -438,7 +437,7 @@ class CandidatesView {
438437
}
439438

440439
getHeight(element: NewSymbolName): number {
441-
return that.candidateViewHeight;
440+
return that._candidateViewHeight;
442441
}
443442
};
444443

@@ -483,9 +482,9 @@ class CandidatesView {
483482
this._listWidget.style(defaultListStyles);
484483
}
485484

486-
public get candidateViewHeight(): number {
487-
const { totalHeight } = CandidateView.getLayoutInfo({ lineHeight: this._lineHeight });
488-
return totalHeight;
485+
dispose() {
486+
this._listWidget.dispose();
487+
this._disposables.dispose();
489488
}
490489

491490
// height - max height allowed by parent element
@@ -496,18 +495,12 @@ class CandidatesView {
496495
}
497496
}
498497

499-
private _pickListHeight(nCandidates: number) {
500-
const heightToFitAllCandidates = this.candidateViewHeight * nCandidates;
501-
const height = Math.min(heightToFitAllCandidates, this._availableHeight, this.candidateViewHeight * 7 /* max # of candidates we want to show at once */);
502-
return height;
503-
}
504-
505498
public setCandidates(candidates: NewSymbolName[]): void {
506499
const height = this._pickListHeight(candidates.length);
507500

508501
this._listWidget.splice(0, 0, candidates);
509502

510-
this._listWidget.layout(height);
503+
this._listWidget.layout(height, this._pickListWidth(candidates));
511504

512505
this._listContainer.style.height = `${height}px`;
513506
}
@@ -571,10 +564,21 @@ class CandidatesView {
571564
return focusedIx > 0;
572565
}
573566

574-
dispose() {
575-
this._listWidget.dispose();
576-
this._disposables.dispose();
567+
private get _candidateViewHeight(): number {
568+
const { totalHeight } = CandidateView.getLayoutInfo({ lineHeight: this._lineHeight });
569+
return totalHeight;
570+
}
571+
572+
private _pickListHeight(nCandidates: number) {
573+
const heightToFitAllCandidates = this._candidateViewHeight * nCandidates;
574+
const height = Math.min(heightToFitAllCandidates, this._availableHeight, this._candidateViewHeight * 7 /* max # of candidates we want to show at once */);
575+
return height;
577576
}
577+
578+
private _pickListWidth(candidates: NewSymbolName[]): number {
579+
return Math.max(...candidates.map(c => c.newSymbolName.length)) * 7 /* approximate # of pixes taken by a single character */;
580+
}
581+
578582
}
579583

580584
class CandidateView {

0 commit comments

Comments
 (0)