diff --git a/src/vs/workbench/services/hover/browser/hover.ts b/src/vs/workbench/services/hover/browser/hover.ts index a504b379d65cd..f696ebd64e7a8 100644 --- a/src/vs/workbench/services/hover/browser/hover.ts +++ b/src/vs/workbench/services/hover/browser/hover.ts @@ -109,4 +109,10 @@ export interface IHoverTarget extends IDisposable { * wrapped text. */ readonly targetElements: readonly HTMLElement[]; + + /** + * An optional absolute x coordinate to position the hover with, for example to position the + * hover using `MouseEvent.pageX`. + */ + x?: number; } diff --git a/src/vs/workbench/services/hover/browser/hoverWidget.ts b/src/vs/workbench/services/hover/browser/hoverWidget.ts index 702e4e5143b63..d7135f2d671a5 100644 --- a/src/vs/workbench/services/hover/browser/hoverWidget.ts +++ b/src/vs/workbench/services/hover/browser/hoverWidget.ts @@ -136,9 +136,10 @@ export class HoverWidget extends Widget { this._hover.containerDomNode.classList.remove('right-aligned'); this._hover.contentsDomNode.style.maxHeight = ''; - // Get horizontal alignment and position const targetBounds = this._target.targetElements.map(e => e.getBoundingClientRect()); - const targetLeft = Math.min(...targetBounds.map(e => e.left)); + + // Get horizontal alignment and position + let targetLeft = this._target.x !== undefined ? this._target.x : Math.min(...targetBounds.map(e => e.left)); if (targetLeft + this._hover.containerDomNode.clientWidth >= document.documentElement.clientWidth) { this._x = document.documentElement.clientWidth; this._hover.containerDomNode.classList.add('right-aligned');