Skip to content

Commit 4c57ecb

Browse files
committed
rename suggestions: try no. 3 at fixing width to not hide parts of long suggested names
1 parent 0b58640 commit 4c57ecb

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { addDisposableListener, getClientArea, getDomNodePagePosition, getTotalHeight } from 'vs/base/browser/dom';
6+
import { addDisposableListener, getClientArea, getDomNodePagePosition, getTotalHeight, getTotalWidth } from 'vs/base/browser/dom';
77
import { renderIcon } from 'vs/base/browser/ui/iconLabel/iconLabels';
88
import { IListRenderer, IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
99
import { List } from 'vs/base/browser/ui/list/listWidget';
@@ -238,7 +238,10 @@ export class RenameInputField implements IContentWidget {
238238
totalHeightAvailable = this._nPxAvailableAbove;
239239
}
240240

241-
this._candidatesView!.layout({ height: totalHeightAvailable - labelHeight - inputBoxHeight });
241+
this._candidatesView!.layout({
242+
height: totalHeightAvailable - labelHeight - inputBoxHeight,
243+
width: getTotalWidth(this._input!),
244+
});
242245
}
243246

244247

@@ -429,6 +432,7 @@ class CandidatesView {
429432

430433
private _lineHeight: number;
431434
private _availableHeight: number;
435+
private _minimumWidth: number;
432436

433437
private _disposables: DisposableStore;
434438

@@ -437,6 +441,7 @@ class CandidatesView {
437441
this._disposables = new DisposableStore();
438442

439443
this._availableHeight = 0;
444+
this._minimumWidth = 0;
440445

441446
this._lineHeight = opts.fontInfo.lineHeight;
442447

@@ -505,27 +510,31 @@ class CandidatesView {
505510
}
506511

507512
// height - max height allowed by parent element
508-
public layout({ height }: { height: number }): void {
513+
public layout({ height, width }: { height: number; width: number }): void {
509514
this._availableHeight = height;
510-
if (this._listWidget.length > 0) { // candidates have been set
511-
this._listWidget.layout(this._pickListHeight(this._listWidget.length));
512-
}
515+
this._minimumWidth = width;
516+
this._listContainer.style.width = `${this._minimumWidth}px`;
513517
}
514518

515519
public setCandidates(candidates: NewSymbolName[]): void {
516-
const height = this._pickListHeight(candidates.length);
517520

521+
// insert candidates into list widget
518522
this._listWidget.splice(0, 0, candidates);
519523

520-
const width = Math.max(200, 4 /* padding */ + 16 /* sparkle icon */ + 5 /* margin-left */ + this._pickListWidth(candidates)); // TODO@ulugbekna: approximate calc - clean this up
524+
// adjust list widget layout
525+
const height = this._pickListHeight(candidates.length);
526+
const width = this._pickListWidth(candidates);
527+
521528
this._listWidget.layout(height, width);
522529

530+
// adjust list container layout
523531
this._listContainer.style.height = `${height}px`;
524532
this._listContainer.style.width = `${width}px`;
525533
}
526534

527535
public clearCandidates(): void {
528536
this._listContainer.style.height = '0px';
537+
this._listContainer.style.width = '0px';
529538
this._listWidget.splice(0, this._listWidget.length, []);
530539
}
531540

@@ -599,7 +608,13 @@ class CandidatesView {
599608
}
600609

601610
private _pickListWidth(candidates: NewSymbolName[]): number {
602-
return Math.ceil(Math.max(...candidates.map(c => c.newSymbolName.length)) * 7.2) /* approximate # of pixes taken by a single character */;
611+
const APPROXIMATE_CHAR_WIDTH = 7.2; // approximate # of pixes taken by a single character
612+
const longestCandidateWidth = Math.ceil(Math.max(...candidates.map(c => c.newSymbolName.length)) * APPROXIMATE_CHAR_WIDTH); // TODO@ulugbekna: use editor#typicalCharacterWidth or something
613+
const width = Math.max(
614+
this._minimumWidth,
615+
4 /* padding */ + 16 /* sparkle icon */ + 5 /* margin-left */ + longestCandidateWidth + 10 /* (possibly visible) scrollbar width */ // TODO@ulugbekna: approximate calc - clean this up
616+
);
617+
return width;
603618
}
604619

605620
}

0 commit comments

Comments
 (0)