Skip to content

Commit

Permalink
Fixes #69391: Reserve extra bottom padding when the hover has a horiz…
Browse files Browse the repository at this point in the history
…ontal scrollbar
  • Loading branch information
alexdima committed Jan 27, 2022
1 parent 1c2f442 commit be5b4fc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/vs/base/browser/ui/hover/hoverWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class HoverWidget extends Disposable {

public readonly containerDomNode: HTMLElement;
public readonly contentsDomNode: HTMLElement;
private readonly _scrollbar: DomScrollableElement;
public readonly scrollbar: DomScrollableElement;

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

this._scrollbar = this._register(new DomScrollableElement(this.contentsDomNode, {
this.scrollbar = this._register(new DomScrollableElement(this.contentsDomNode, {
consumeMouseWheelIfScrollbarIsNeeded: true
}));
this.containerDomNode.appendChild(this._scrollbar.getDomNode());
this.containerDomNode.appendChild(this.scrollbar.getDomNode());
}

public onContentsChanged(): void {
this._scrollbar.scanDomNode();
this.scrollbar.scanDomNode();
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/vs/base/browser/ui/scrollbar/scrollableElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ export abstract class AbstractScrollableElement extends Widget {
private readonly _onWillScroll = this._register(new Emitter<ScrollEvent>());
public readonly onWillScroll: Event<ScrollEvent> = this._onWillScroll.event;

public get options(): Readonly<ScrollableElementResolvedOptions> {
return this._options;
}

protected constructor(element: HTMLElement, options: ScrollableElementCreationOptions, scrollable: Scrollable) {
super();
element.style.overflow = 'hidden';
Expand Down
17 changes: 15 additions & 2 deletions src/vs/editor/contrib/hover/browser/contentHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,11 @@ export class ContentHoverWidget extends Disposable implements IContentWidget {

this._hover.contentsDomNode.textContent = '';
this._hover.contentsDomNode.appendChild(node);
this._hover.contentsDomNode.style.paddingBottom = '';
this._updateFont();

this._editor.layoutContentWidget(this);
this._hover.onContentsChanged();
this.onContentsChanged();

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

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

public onContentsChanged(): void {
this._hover.onContentsChanged();

const scrollDimensions = this._hover.scrollbar.getScrollDimensions();
const hasHorizontalScrollbar = (scrollDimensions.scrollWidth > scrollDimensions.width);
if (hasHorizontalScrollbar) {
// There is just a horizontal scrollbar
const extraBottomPadding = `${this._hover.scrollbar.options.horizontalScrollbarSize}px`;
if (this._hover.contentsDomNode.style.paddingBottom !== extraBottomPadding) {
this._hover.contentsDomNode.style.paddingBottom = extraBottomPadding;
this._editor.layoutContentWidget(this);
this._hover.onContentsChanged();
}
}
}

public clear(): void {
Expand Down

0 comments on commit be5b4fc

Please sign in to comment.