@@ -58,13 +58,14 @@ class CodeLensContentWidget implements editorBrowser.IContentWidget {
5858 private readonly _id : string ;
5959 private readonly _domNode : HTMLElement ;
6060 private readonly _editor : editorBrowser . ICodeEditor ;
61+ private readonly _commands = new Map < string , Command > ( ) ;
6162
6263 private _widgetPosition : editorBrowser . IContentWidgetPosition ;
63- private _commands : { [ id : string ] : Command } = Object . create ( null ) ;
6464
6565 constructor (
6666 editor : editorBrowser . ICodeEditor ,
67- symbolRange : Range
67+ symbolRange : Range ,
68+ data : ICodeLensData [ ]
6869 ) {
6970 this . _id = 'codeLensWidget' + ( ++ CodeLensContentWidget . _idPool ) ;
7071 this . _editor = editor ;
@@ -74,9 +75,8 @@ class CodeLensContentWidget implements editorBrowser.IContentWidget {
7475 this . _domNode = document . createElement ( 'span' ) ;
7576 this . _domNode . innerHTML = ' ' ;
7677 dom . addClass ( this . _domNode , 'codelens-decoration' ) ;
77- dom . addClass ( this . _domNode , 'invisible-cl' ) ;
7878 this . updateHeight ( ) ;
79- this . updateVisibility ( ) ;
79+ this . withCommands ( data . map ( data => data . symbol ) , false ) ;
8080 }
8181
8282 updateHeight ( ) : void {
@@ -88,15 +88,9 @@ class CodeLensContentWidget implements editorBrowser.IContentWidget {
8888 this . _domNode . innerHTML = ' ' ;
8989 }
9090
91- updateVisibility ( ) : void {
92- if ( this . isVisible ( ) ) {
93- dom . removeClass ( this . _domNode , 'invisible-cl' ) ;
94- dom . addClass ( this . _domNode , 'fadein' ) ;
95- }
96- }
91+ withCommands ( inSymbols : Array < ICodeLensSymbol | undefined | null > , animate : boolean ) : void {
92+ this . _commands . clear ( ) ;
9793
98- withCommands ( inSymbols : Array < ICodeLensSymbol | undefined | null > ) : void {
99- this . _commands = Object . create ( null ) ;
10094 const symbols = coalesce ( inSymbols ) ;
10195 if ( isFalsyOrEmpty ( symbols ) ) {
10296 this . _domNode . innerHTML = '<span>no commands</span>' ;
@@ -111,21 +105,25 @@ class CodeLensContentWidget implements editorBrowser.IContentWidget {
111105 let part : string ;
112106 if ( command . id ) {
113107 part = `<a id=${ i } >${ title } </a>` ;
114- this . _commands [ i ] = command ;
108+ this . _commands . set ( String ( i ) , command ) ;
115109 } else {
116110 part = `<span>${ title } </span>` ;
117111 }
118112 html . push ( part ) ;
119113 }
120114 }
121115
116+ const wasEmpty = this . _domNode . innerHTML === '' || this . _domNode . innerHTML === ' ' ;
122117 this . _domNode . innerHTML = html . join ( '<span> | </span>' ) ;
123118 this . _editor . layoutContentWidget ( this ) ;
119+ if ( wasEmpty && animate ) {
120+ dom . addClass ( this . _domNode , 'fadein' ) ;
121+ }
124122 }
125123
126124 getCommand ( link : HTMLLinkElement ) : Command | undefined {
127125 return link . parentElement === this . _domNode
128- ? this . _commands [ link . id ]
126+ ? this . _commands . get ( link . id )
129127 : undefined ;
130128 }
131129
@@ -228,7 +226,7 @@ export class CodeLens {
228226 } ) ;
229227
230228 if ( range ) {
231- this . _contentWidget = new CodeLensContentWidget ( editor , range ) ;
229+ this . _contentWidget = new CodeLensContentWidget ( editor , range , this . _data ) ;
232230 this . _viewZone = new CodeLensViewZone ( range . startLineNumber - 1 , updateCallback ) ;
233231
234232 this . _viewZoneId = viewZoneChangeAccessor . addZone ( this . _viewZone ) ;
@@ -273,7 +271,6 @@ export class CodeLens {
273271 }
274272
275273 computeIfNecessary ( model : ITextModel ) : ICodeLensData [ ] | null {
276- this . _contentWidget . updateVisibility ( ) ; // trigger the fade in
277274 if ( ! this . _contentWidget . isVisible ( ) ) {
278275 return null ;
279276 }
@@ -289,7 +286,7 @@ export class CodeLens {
289286 }
290287
291288 updateCommands ( symbols : Array < ICodeLensSymbol | undefined | null > ) : void {
292- this . _contentWidget . withCommands ( symbols ) ;
289+ this . _contentWidget . withCommands ( symbols , true ) ;
293290 for ( let i = 0 ; i < this . _data . length ; i ++ ) {
294291 const resolved = symbols [ i ] ;
295292 if ( resolved ) {
0 commit comments