Skip to content

Commit 31c094c

Browse files
committed
Delays hover first show and adds esc to close
1 parent af42f6c commit 31c094c

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/webviews/apps/plus/graph/hover/graphHover.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { css, html } from 'lit';
33
import { customElement, property } from 'lit/decorators.js';
44
import { until } from 'lit/directives/until.js';
55
import type { DidGetRowHoverParams } from '../../../../../plus/webviews/graph/protocol';
6+
import type { Deferrable } from '../../../../../system/function';
7+
import { debounce } from '../../../../../system/function';
68
import { isPromise } from '../../../../../system/promise';
79
import { GlElement } from '../../../shared/components/element';
810
import type { GlPopover } from '../../../shared/components/overlays/popover.react';
@@ -82,10 +84,12 @@ export class GlGraphHover extends GlElement {
8284
this.hide();
8385
};
8486

87+
private _showCoreDebounced: Deferrable<GlGraphHover['showCore']> | undefined = undefined;
88+
8589
onRowHovered(row: GraphRow, anchor: Anchor) {
8690
clearTimeout(this.unhoverTimer);
8791
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
8993
if (this.hoveredSha === row.sha && this.open) return;
9094

9195
this.hoveredSha = row.sha;
@@ -113,7 +117,12 @@ export class GlGraphHover extends GlElement {
113117
}
114118
}
115119

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+
}
117126
}
118127

119128
onRowUnhovered(row: GraphRow, relatedTarget: EventTarget | null) {
@@ -130,6 +139,13 @@ export class GlGraphHover extends GlElement {
130139
this.unhoverTimer = setTimeout(() => this.hide(), 250);
131140
}
132141

142+
onWindowKeydown = (e: KeyboardEvent) => {
143+
if (e.key === 'Escape') {
144+
e.stopPropagation();
145+
this.hide();
146+
}
147+
};
148+
133149
private showCore(
134150
anchor: string | HTMLElement | { getBoundingClientRect: () => Omit<DOMRect, 'toJSON'> },
135151
markdown: Promise<string | undefined> | string | undefined,
@@ -150,11 +166,14 @@ export class GlGraphHover extends GlElement {
150166
this.markdown = markdown;
151167
this.open = true;
152168
this.parentElement?.addEventListener('mouseleave', this.onParentMouseLeave);
169+
window.addEventListener('keydown', this.onWindowKeydown);
153170
}
154171

155172
hide() {
173+
this._showCoreDebounced?.cancel();
156174
clearTimeout(this.unhoverTimer);
157175
this.parentElement?.removeEventListener('mouseleave', this.onParentMouseLeave);
176+
window.removeEventListener('keydown', this.onWindowKeydown);
158177

159178
this.hoveredSha = undefined;
160179
this.markdown = undefined;

0 commit comments

Comments
 (0)