@@ -3,6 +3,8 @@ import { css, html } from 'lit';
3
3
import { customElement , property } from 'lit/decorators.js' ;
4
4
import { until } from 'lit/directives/until.js' ;
5
5
import type { DidGetRowHoverParams } from '../../../../../plus/webviews/graph/protocol' ;
6
+ import type { Deferrable } from '../../../../../system/function' ;
7
+ import { debounce } from '../../../../../system/function' ;
6
8
import { isPromise } from '../../../../../system/promise' ;
7
9
import { GlElement } from '../../../shared/components/element' ;
8
10
import type { GlPopover } from '../../../shared/components/overlays/popover.react' ;
@@ -82,10 +84,12 @@ export class GlGraphHover extends GlElement {
82
84
this . hide ( ) ;
83
85
} ;
84
86
87
+ private _showCoreDebounced : Deferrable < GlGraphHover [ 'showCore' ] > | undefined = undefined ;
88
+
85
89
onRowHovered ( row : GraphRow , anchor : Anchor ) {
86
90
clearTimeout ( this . unhoverTimer ) ;
87
91
if ( this . requestMarkdown == null ) return ;
88
- // Break if we are already showing the hover for thesame row
92
+ // Break if we are already showing the hover for the same row
89
93
if ( this . hoveredSha === row . sha && this . open ) return ;
90
94
91
95
this . hoveredSha = row . sha ;
@@ -113,7 +117,12 @@ export class GlGraphHover extends GlElement {
113
117
}
114
118
}
115
119
116
- this . showCore ( anchor , markdown ) ;
120
+ if ( this . open ) {
121
+ this . showCore ( anchor , markdown ) ;
122
+ } else {
123
+ this . _showCoreDebounced ??= debounce ( this . showCore . bind ( this ) , 500 ) ;
124
+ this . _showCoreDebounced ( anchor , markdown ) ;
125
+ }
117
126
}
118
127
119
128
onRowUnhovered ( row : GraphRow , relatedTarget : EventTarget | null ) {
@@ -130,6 +139,13 @@ export class GlGraphHover extends GlElement {
130
139
this . unhoverTimer = setTimeout ( ( ) => this . hide ( ) , 250 ) ;
131
140
}
132
141
142
+ onWindowKeydown = ( e : KeyboardEvent ) => {
143
+ if ( e . key === 'Escape' ) {
144
+ e . stopPropagation ( ) ;
145
+ this . hide ( ) ;
146
+ }
147
+ } ;
148
+
133
149
private showCore (
134
150
anchor : string | HTMLElement | { getBoundingClientRect : ( ) => Omit < DOMRect , 'toJSON' > } ,
135
151
markdown : Promise < string | undefined > | string | undefined ,
@@ -150,11 +166,14 @@ export class GlGraphHover extends GlElement {
150
166
this . markdown = markdown ;
151
167
this . open = true ;
152
168
this . parentElement ?. addEventListener ( 'mouseleave' , this . onParentMouseLeave ) ;
169
+ window . addEventListener ( 'keydown' , this . onWindowKeydown ) ;
153
170
}
154
171
155
172
hide ( ) {
173
+ this . _showCoreDebounced ?. cancel ( ) ;
156
174
clearTimeout ( this . unhoverTimer ) ;
157
175
this . parentElement ?. removeEventListener ( 'mouseleave' , this . onParentMouseLeave ) ;
176
+ window . removeEventListener ( 'keydown' , this . onWindowKeydown ) ;
158
177
159
178
this . hoveredSha = undefined ;
160
179
this . markdown = undefined ;
0 commit comments