3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { addDisposableListener , getClientArea , getDomNodePagePosition , getTotalHeight } from 'vs/base/browser/dom' ;
6
+ import { addDisposableListener , getClientArea , getDomNodePagePosition , getTotalHeight , getTotalWidth } from 'vs/base/browser/dom' ;
7
7
import { renderIcon } from 'vs/base/browser/ui/iconLabel/iconLabels' ;
8
8
import { IListRenderer , IListVirtualDelegate } from 'vs/base/browser/ui/list/list' ;
9
9
import { List } from 'vs/base/browser/ui/list/listWidget' ;
@@ -238,7 +238,10 @@ export class RenameInputField implements IContentWidget {
238
238
totalHeightAvailable = this . _nPxAvailableAbove ;
239
239
}
240
240
241
- this . _candidatesView ! . layout ( { height : totalHeightAvailable - labelHeight - inputBoxHeight } ) ;
241
+ this . _candidatesView ! . layout ( {
242
+ height : totalHeightAvailable - labelHeight - inputBoxHeight ,
243
+ width : getTotalWidth ( this . _input ! ) ,
244
+ } ) ;
242
245
}
243
246
244
247
@@ -429,6 +432,7 @@ class CandidatesView {
429
432
430
433
private _lineHeight : number ;
431
434
private _availableHeight : number ;
435
+ private _minimumWidth : number ;
432
436
433
437
private _disposables : DisposableStore ;
434
438
@@ -437,6 +441,7 @@ class CandidatesView {
437
441
this . _disposables = new DisposableStore ( ) ;
438
442
439
443
this . _availableHeight = 0 ;
444
+ this . _minimumWidth = 0 ;
440
445
441
446
this . _lineHeight = opts . fontInfo . lineHeight ;
442
447
@@ -505,27 +510,31 @@ class CandidatesView {
505
510
}
506
511
507
512
// height - max height allowed by parent element
508
- public layout ( { height } : { height : number } ) : void {
513
+ public layout ( { height, width } : { height : number ; width : number } ) : void {
509
514
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` ;
513
517
}
514
518
515
519
public setCandidates ( candidates : NewSymbolName [ ] ) : void {
516
- const height = this . _pickListHeight ( candidates . length ) ;
517
520
521
+ // insert candidates into list widget
518
522
this . _listWidget . splice ( 0 , 0 , candidates ) ;
519
523
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
+
521
528
this . _listWidget . layout ( height , width ) ;
522
529
530
+ // adjust list container layout
523
531
this . _listContainer . style . height = `${ height } px` ;
524
532
this . _listContainer . style . width = `${ width } px` ;
525
533
}
526
534
527
535
public clearCandidates ( ) : void {
528
536
this . _listContainer . style . height = '0px' ;
537
+ this . _listContainer . style . width = '0px' ;
529
538
this . _listWidget . splice ( 0 , this . _listWidget . length , [ ] ) ;
530
539
}
531
540
@@ -599,7 +608,13 @@ class CandidatesView {
599
608
}
600
609
601
610
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 ;
603
618
}
604
619
605
620
}
0 commit comments