Skip to content

Commit

Permalink
Allow hover x to be overridden
Browse files Browse the repository at this point in the history
Fixes #104058
  • Loading branch information
Tyriar committed Aug 12, 2020
1 parent 0b03a79 commit 115d7cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/vs/workbench/services/hover/browser/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 3 additions & 2 deletions src/vs/workbench/services/hover/browser/hoverWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 115d7cf

Please sign in to comment.