@@ -141,6 +141,10 @@ export class HoverCM extends CodeMirrorIntegration {
141141 return this . settings . composite . modifierKey ;
142142 }
143143
144+ protected get isHoverAutomatic ( ) : boolean {
145+ return this . settings . composite . autoActivate ;
146+ }
147+
144148 get lab_integration ( ) {
145149 return super . lab_integration as HoverLabIntegration ;
146150 }
@@ -387,15 +391,19 @@ export class HoverCM extends CodeMirrorIntegration {
387391 protected async _updateUnderlineAndTooltip (
388392 event : MouseEvent
389393 ) : Promise < boolean > {
390- const target = event . target as HTMLElement ;
394+ const target = event . target ;
391395
392396 // if over an empty space in a line (and not over a token) then not worth checking
393- if ( target . classList . contains ( 'CodeMirror-line' ) ) {
397+ if (
398+ target == null ||
399+ ( target as HTMLElement ) . classList . contains ( 'CodeMirror-line' )
400+ ) {
394401 this . remove_range_highlight ( ) ;
395402 return false ;
396403 }
397404
398- const show_tooltip = getModifierState ( event , this . modifierKey ) ;
405+ const show_tooltip =
406+ this . isHoverAutomatic || getModifierState ( event , this . modifierKey ) ;
399407
400408 // currently the events are coming from notebook panel; ideally these would be connected to individual cells,
401409 // (only cells with code) instead, but this is more complex to implement right. In any case filtering
@@ -445,6 +453,7 @@ export class HoverCM extends CodeMirrorIntegration {
445453 ] ) ;
446454 }
447455 let response_data = this . restore_from_cache ( document , virtual_position ) ;
456+ let delay_ms = this . settings . composite . delay ;
448457
449458 if ( response_data == null ) {
450459 const ce_editor =
@@ -493,12 +502,21 @@ export class HoverCM extends CodeMirrorIntegration {
493502 } ;
494503
495504 this . cache . store ( response_data ) ;
505+ delay_ms = Math . max (
506+ 0 ,
507+ this . settings . composite . delay -
508+ this . settings . composite . throttlerDelay
509+ ) ;
496510 } else {
497511 this . remove_range_highlight ( ) ;
498512 return false ;
499513 }
500514 }
501515
516+ if ( this . isHoverAutomatic ) {
517+ await new Promise ( resolve => setTimeout ( resolve , delay_ms ) ) ;
518+ }
519+
502520 return this . handleResponse ( response_data , root_position , show_tooltip ) ;
503521 } else {
504522 return true ;
0 commit comments