Skip to content

Commit e63406a

Browse files
rzhao271Tyriar
andauthored
Add max height to hover (microsoft#164093)
Co-authored-by: Daniel Imms <[email protected]>
1 parent 2ebd334 commit e63406a

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/vs/workbench/services/hover/browser/hoverWidget.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,11 @@ export class HoverWidget extends Widget {
258258
}
259259
};
260260

261+
// These calls adjust the position depending on spacing.
261262
this.adjustHorizontalHoverPosition(targetRect);
262263
this.adjustVerticalHoverPosition(targetRect);
264+
// This call limits the maximum height of the hover.
265+
this.adjustHoverMaxHeight(targetRect);
263266

264267
// Offset the hover position if there is a pointer so it aligns with the target element
265268
this._hoverContainer.style.padding = '';
@@ -410,19 +413,9 @@ export class HoverWidget extends Widget {
410413
}
411414

412415
private adjustVerticalHoverPosition(target: TargetRect): void {
413-
// Do not adjust vertical hover position if y cordiante is provided
414-
if (this._target.y !== undefined) {
415-
return;
416-
}
417-
418-
// When force position is enabled, restrict max height
419-
if (this._forcePosition) {
420-
const padding = (this._hoverPointer ? Constants.PointerSize : 0) + Constants.HoverBorderWidth;
421-
if (this._hoverPosition === HoverPosition.ABOVE) {
422-
this._hover.containerDomNode.style.maxHeight = `${target.top - padding}px`;
423-
} else if (this._hoverPosition === HoverPosition.BELOW) {
424-
this._hover.containerDomNode.style.maxHeight = `${window.innerHeight - target.bottom - padding}px`;
425-
}
416+
// Do not adjust vertical hover position if the y coordinate is provided
417+
// or the position is forced
418+
if (this._target.y !== undefined || this._forcePosition) {
426419
return;
427420
}
428421

@@ -443,6 +436,25 @@ export class HoverWidget extends Widget {
443436
}
444437
}
445438

439+
private adjustHoverMaxHeight(target: TargetRect): void {
440+
let maxHeight = window.innerHeight / 2;
441+
442+
// When force position is enabled, restrict max height
443+
if (this._forcePosition) {
444+
const padding = (this._hoverPointer ? Constants.PointerSize : 0) + Constants.HoverBorderWidth;
445+
if (this._hoverPosition === HoverPosition.ABOVE) {
446+
maxHeight = Math.min(maxHeight, target.top - padding);
447+
} else if (this._hoverPosition === HoverPosition.BELOW) {
448+
maxHeight = Math.min(maxHeight, window.innerHeight - target.bottom - padding);
449+
}
450+
}
451+
452+
// Make sure not to accidentally enlarge the hover when setting a maxHeight for it
453+
maxHeight = Math.min(maxHeight, this._hover.containerDomNode.clientHeight);
454+
455+
this._hover.containerDomNode.style.maxHeight = `${maxHeight}px`;
456+
}
457+
446458
private setHoverPointerPosition(target: TargetRect): void {
447459
if (!this._hoverPointer) {
448460
return;

src/vs/workbench/services/hover/browser/media/hover.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/* Must be higher than sash's z-index and terminal canvases */
1111
z-index: 40;
1212
overflow: hidden;
13+
overflow-y: auto;
1314
max-width: 700px;
1415
}
1516

0 commit comments

Comments
 (0)