@@ -156,8 +156,8 @@ export class GlyphHoverWidget extends Widget implements editorBrowser.IOverlayWi
156156
157157 private _id : string ;
158158 protected _editor : editorBrowser . ICodeEditor ;
159- protected _isVisible : boolean ;
160- protected _domNode : HTMLElement ;
159+ private _isVisible : boolean ;
160+ private _domNode : HTMLElement ;
161161 protected _showAtLineNumber : number ;
162162
163163 constructor ( id : string , editor : editorBrowser . ICodeEditor ) {
@@ -167,23 +167,30 @@ export class GlyphHoverWidget extends Widget implements editorBrowser.IOverlayWi
167167 this . _isVisible = false ;
168168
169169 this . _domNode = document . createElement ( 'div' ) ;
170- this . _domNode . className = 'monaco-editor-hover monaco-editor-background' ;
171- this . _domNode . style . display = 'none' ;
170+ this . _domNode . className = 'monaco-editor-hover hidden' ;
172171 this . _domNode . setAttribute ( 'aria-hidden' , 'true' ) ;
173172 this . _domNode . setAttribute ( 'role' , 'presentation' ) ;
174173
175174 this . _showAtLineNumber = - 1 ;
176175
177- this . _editor . applyFontInfo ( this . _domNode ) ;
178176 this . _register ( this . _editor . onDidChangeConfiguration ( ( e :IConfigurationChangedEvent ) => {
179177 if ( e . fontInfo ) {
180- this . _editor . applyFontInfo ( this . _domNode ) ;
178+ this . updateFont ( ) ;
181179 }
182180 } ) ) ;
183181
184182 this . _editor . addOverlayWidget ( this ) ;
185183 }
186184
185+ protected get isVisible ( ) : boolean {
186+ return this . _isVisible ;
187+ }
188+
189+ protected set isVisible ( value : boolean ) {
190+ this . _isVisible = value ;
191+ toggleClass ( this . _domNode , 'hidden' , ! this . _isVisible ) ;
192+ }
193+
187194 public getId ( ) : string {
188195 return this . _id ;
189196 }
@@ -195,25 +202,26 @@ export class GlyphHoverWidget extends Widget implements editorBrowser.IOverlayWi
195202 public showAt ( lineNumber : number ) : void {
196203 this . _showAtLineNumber = lineNumber ;
197204
198- if ( ! this . _isVisible ) {
199- this . _isVisible = true ;
200- this . _domNode . style . display = 'block' ;
205+ if ( ! this . isVisible ) {
206+ this . isVisible = true ;
201207 }
202208
203- let editorLayout = this . _editor . getLayoutInfo ( ) ;
204- let topForLineNumber = this . _editor . getTopForLineNumber ( this . _showAtLineNumber ) ;
205- let editorScrollTop = this . _editor . getScrollTop ( ) ;
209+ const editorLayout = this . _editor . getLayoutInfo ( ) ;
210+ const topForLineNumber = this . _editor . getTopForLineNumber ( this . _showAtLineNumber ) ;
211+ const editorScrollTop = this . _editor . getScrollTop ( ) ;
212+ const lineHeight = this . _editor . getConfiguration ( ) . lineHeight ;
213+ const nodeHeight = this . _domNode . clientHeight ;
214+ const top = topForLineNumber - editorScrollTop - ( ( nodeHeight - lineHeight ) / 2 ) ;
206215
207- this . _domNode . style . left = ( editorLayout . glyphMarginLeft + editorLayout . glyphMarginWidth ) + 'px' ;
208- this . _domNode . style . top = ( topForLineNumber - editorScrollTop ) + 'px' ;
216+ this . _domNode . style . left = ` ${ editorLayout . glyphMarginLeft + editorLayout . glyphMarginWidth } px` ;
217+ this . _domNode . style . top = ` ${ Math . max ( Math . round ( top ) , 0 ) } px` ;
209218 }
210219
211220 public hide ( ) : void {
212- if ( ! this . _isVisible ) {
221+ if ( ! this . isVisible ) {
213222 return ;
214223 }
215- this . _isVisible = false ;
216- this . _domNode . style . display = 'none' ;
224+ this . isVisible = false ;
217225 }
218226
219227 public getPosition ( ) :editorBrowser . IOverlayWidgetPosition {
@@ -224,4 +232,17 @@ export class GlyphHoverWidget extends Widget implements editorBrowser.IOverlayWi
224232 this . _editor . removeOverlayWidget ( this ) ;
225233 super . dispose ( ) ;
226234 }
235+
236+ private updateFont ( ) : void {
237+ const codeTags : HTMLPhraseElement [ ] = Array . prototype . slice . call ( this . _domNode . getElementsByTagName ( 'code' ) ) ;
238+ const codeClasses : HTMLElement [ ] = Array . prototype . slice . call ( this . _domNode . getElementsByClassName ( 'code' ) ) ;
239+
240+ [ ...codeTags , ...codeClasses ] . forEach ( node => this . _editor . applyFontInfo ( node ) ) ;
241+ }
242+
243+ protected updateContents ( node : Node ) : void {
244+ this . _domNode . textContent = '' ;
245+ this . _domNode . appendChild ( node ) ;
246+ this . updateFont ( ) ;
247+ }
227248}
0 commit comments