Skip to content

Commit be5b4fc

Browse files
committed
Fixes microsoft#69391: Reserve extra bottom padding when the hover has a horizontal scrollbar
1 parent 1c2f442 commit be5b4fc

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/vs/base/browser/ui/hover/hoverWidget.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class HoverWidget extends Disposable {
1818

1919
public readonly containerDomNode: HTMLElement;
2020
public readonly contentsDomNode: HTMLElement;
21-
private readonly _scrollbar: DomScrollableElement;
21+
public readonly scrollbar: DomScrollableElement;
2222

2323
constructor() {
2424
super();
@@ -31,14 +31,14 @@ export class HoverWidget extends Disposable {
3131
this.contentsDomNode = document.createElement('div');
3232
this.contentsDomNode.className = 'monaco-hover-content';
3333

34-
this._scrollbar = this._register(new DomScrollableElement(this.contentsDomNode, {
34+
this.scrollbar = this._register(new DomScrollableElement(this.contentsDomNode, {
3535
consumeMouseWheelIfScrollbarIsNeeded: true
3636
}));
37-
this.containerDomNode.appendChild(this._scrollbar.getDomNode());
37+
this.containerDomNode.appendChild(this.scrollbar.getDomNode());
3838
}
3939

4040
public onContentsChanged(): void {
41-
this._scrollbar.scanDomNode();
41+
this.scrollbar.scanDomNode();
4242
}
4343
}
4444

src/vs/base/browser/ui/scrollbar/scrollableElement.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ export abstract class AbstractScrollableElement extends Widget {
175175
private readonly _onWillScroll = this._register(new Emitter<ScrollEvent>());
176176
public readonly onWillScroll: Event<ScrollEvent> = this._onWillScroll.event;
177177

178+
public get options(): Readonly<ScrollableElementResolvedOptions> {
179+
return this._options;
180+
}
181+
178182
protected constructor(element: HTMLElement, options: ScrollableElementCreationOptions, scrollable: Scrollable) {
179183
super();
180184
element.style.overflow = 'hidden';

src/vs/editor/contrib/hover/browser/contentHover.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,11 @@ export class ContentHoverWidget extends Disposable implements IContentWidget {
417417

418418
this._hover.contentsDomNode.textContent = '';
419419
this._hover.contentsDomNode.appendChild(node);
420+
this._hover.contentsDomNode.style.paddingBottom = '';
420421
this._updateFont();
421422

422423
this._editor.layoutContentWidget(this);
423-
this._hover.onContentsChanged();
424+
this.onContentsChanged();
424425

425426
// Simply force a synchronous render on the editor
426427
// such that the widget does not really render with left = '0px'
@@ -429,7 +430,7 @@ export class ContentHoverWidget extends Disposable implements IContentWidget {
429430
// See https://github.com/microsoft/vscode/issues/140339
430431
// TODO: Doing a second layout of the hover after force rendering the editor
431432
this._editor.layoutContentWidget(this);
432-
this._hover.onContentsChanged();
433+
this.onContentsChanged();
433434

434435
if (visibleData.stoleFocus) {
435436
this._hover.containerDomNode.focus();
@@ -452,6 +453,18 @@ export class ContentHoverWidget extends Disposable implements IContentWidget {
452453

453454
public onContentsChanged(): void {
454455
this._hover.onContentsChanged();
456+
457+
const scrollDimensions = this._hover.scrollbar.getScrollDimensions();
458+
const hasHorizontalScrollbar = (scrollDimensions.scrollWidth > scrollDimensions.width);
459+
if (hasHorizontalScrollbar) {
460+
// There is just a horizontal scrollbar
461+
const extraBottomPadding = `${this._hover.scrollbar.options.horizontalScrollbarSize}px`;
462+
if (this._hover.contentsDomNode.style.paddingBottom !== extraBottomPadding) {
463+
this._hover.contentsDomNode.style.paddingBottom = extraBottomPadding;
464+
this._editor.layoutContentWidget(this);
465+
this._hover.onContentsChanged();
466+
}
467+
}
455468
}
456469

457470
public clear(): void {

0 commit comments

Comments
 (0)