Skip to content

Commit 5ccc2db

Browse files
authored
Remove the special handling of the horizontal scrollbar in content hover widget (microsoft#210450)
* doing CSS changes allowing us to remove the special handling of the horizontal scrollbar * removing compilation error
1 parent 796d527 commit 5ccc2db

File tree

5 files changed

+28
-41
lines changed

5 files changed

+28
-41
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
.monaco-hover .hover-row.status-bar .actions {
123123
display: flex;
124124
padding: 0px 8px;
125+
width: 100%;
125126
}
126127

127128
.monaco-hover .hover-row.status-bar .actions .action-container {
@@ -170,6 +171,12 @@
170171
display: inline-block;
171172
}
172173

174+
.monaco-hover-content {
175+
padding-right: 2px;
176+
padding-bottom: 2px;
177+
box-sizing: border-box;
178+
}
179+
173180
.monaco-hover-content .action-container a {
174181
-webkit-user-select: none;
175182
user-select: none;

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ class ContentHoverVisibleData {
481481
}
482482

483483
const HORIZONTAL_SCROLLING_BY = 30;
484-
const SCROLLBAR_WIDTH = 10;
485484
const CONTAINER_HEIGHT_PADDING = 6;
486485

487486
export class ContentHoverWidget extends ResizableContentWidget {
@@ -601,30 +600,11 @@ export class ContentHoverWidget extends ResizableContentWidget {
601600
this._layoutContentWidget();
602601
}
603602

604-
private _hasHorizontalScrollbar(): boolean {
605-
const scrollDimensions = this._hover.scrollbar.getScrollDimensions();
606-
const hasHorizontalScrollbar = scrollDimensions.scrollWidth > scrollDimensions.width;
607-
return hasHorizontalScrollbar;
608-
}
609-
610-
private _adjustContentsBottomPadding(): void {
611-
const contentsDomNode = this._hover.contentsDomNode;
612-
const extraBottomPadding = `${this._hover.scrollbar.options.horizontalScrollbarSize}px`;
613-
if (contentsDomNode.style.paddingBottom !== extraBottomPadding) {
614-
contentsDomNode.style.paddingBottom = extraBottomPadding;
615-
}
616-
}
617-
618603
private _setAdjustedHoverWidgetDimensions(size: dom.Dimension): void {
619604
this._setHoverWidgetMaxDimensions('none', 'none');
620605
const width = size.width;
621606
const height = size.height;
622607
this._setHoverWidgetDimensions(width, height);
623-
// measure if widget has horizontal scrollbar after setting the dimensions
624-
if (this._hasHorizontalScrollbar()) {
625-
this._adjustContentsBottomPadding();
626-
this._setContentsDomNodeDimensions(width, height - SCROLLBAR_WIDTH);
627-
}
628608
}
629609

630610
private _updateResizableNodeMaxDimensions(): void {
@@ -665,9 +645,6 @@ export class ContentHoverWidget extends ResizableContentWidget {
665645
maximumHeight += hoverPart.clientHeight;
666646
});
667647

668-
if (this._hasHorizontalScrollbar()) {
669-
maximumHeight += SCROLLBAR_WIDTH;
670-
}
671648
return Math.min(availableSpace, maximumHeight);
672649
}
673650

@@ -857,14 +834,6 @@ export class ContentHoverWidget extends ResizableContentWidget {
857834
this._setHoverWidgetDimensions('auto', 'auto');
858835
}
859836

860-
private _adjustHoverHeightForScrollbar(height: number) {
861-
const containerDomNode = this._hover.containerDomNode;
862-
const contentsDomNode = this._hover.contentsDomNode;
863-
const maxRenderingHeight = this._findMaximumRenderingHeight() ?? Infinity;
864-
this._setContainerDomNodeDimensions(dom.getTotalWidth(containerDomNode), Math.min(maxRenderingHeight, height));
865-
this._setContentsDomNodeDimensions(dom.getTotalWidth(contentsDomNode), Math.min(maxRenderingHeight, height - SCROLLBAR_WIDTH));
866-
}
867-
868837
public setMinimumDimensions(dimensions: dom.Dimension): void {
869838
// We combine the new minimum dimensions with the previous ones
870839
this._minimumSize = new dom.Dimension(
@@ -900,10 +869,6 @@ export class ContentHoverWidget extends ResizableContentWidget {
900869
this._updateMinimumWidth();
901870
this._resizableNode.layout(height, width);
902871

903-
if (this._hasHorizontalScrollbar()) {
904-
this._adjustContentsBottomPadding();
905-
this._adjustHoverHeightForScrollbar(height);
906-
}
907872
if (this._visibleData?.showAtPosition) {
908873
const widgetHeight = dom.getTotalHeight(this._hover.containerDomNode);
909874
this._positionPreference = this._findPositionPreference(widgetHeight, this._visibleData.showAtPosition);

src/vs/editor/contrib/hover/browser/hover.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
color: var(--vscode-textLink-activeForeground);
2323
}
2424

25+
.monaco-editor .monaco-hover .hover-row {
26+
display: flex;
27+
}
28+
29+
.monaco-editor .monaco-hover .hover-row .hover-row-contents {
30+
min-width:0;
31+
display: flex;
32+
flex-direction: column;
33+
}
34+
2535
.monaco-editor .monaco-hover .hover-row .actions {
2636
background-color: var(--vscode-editorHoverWidget-statusBarBackground);
2737
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,21 @@ export class MarkdownHoverParticipant implements IEditorHoverParticipant<Markdow
134134
}
135135

136136
public renderHoverParts(context: IEditorHoverRenderContext, hoverParts: MarkdownHover[]): IDisposable {
137-
return renderMarkdownHovers(context, hoverParts, this._editor, this._languageService, this._openerService);
137+
const renderedMarkdown = $('div.hover-row');
138+
context.fragment.appendChild(renderedMarkdown);
139+
const renderedMarkdownContents = $('div.hover-row-contents');
140+
renderedMarkdown.appendChild(renderedMarkdownContents);
141+
return renderMarkdownHovers(renderedMarkdownContents, hoverParts, this._editor, this._languageService, this._openerService, context.onContentsChanged);
138142
}
139143
}
140144

141145
export function renderMarkdownHovers(
142-
context: IEditorHoverRenderContext,
146+
container: DocumentFragment | HTMLElement,
143147
hoverParts: MarkdownHover[],
144148
editor: ICodeEditor,
145149
languageService: ILanguageService,
146150
openerService: IOpenerService,
151+
onFinishedRendering: () => void
147152
): IDisposable {
148153

149154
// Sort hover parts to keep them stable since they might come in async, out-of-order
@@ -155,16 +160,16 @@ export function renderMarkdownHovers(
155160
if (isEmptyMarkdownString(contents)) {
156161
continue;
157162
}
158-
const markdownHoverElement = $('div.hover-row.markdown-hover');
163+
const markdownHoverElement = $('div.markdown-hover');
159164
const hoverContentsElement = dom.append(markdownHoverElement, $('div.hover-contents'));
160165
const renderer = disposables.add(new MarkdownRenderer({ editor }, languageService, openerService));
161166
disposables.add(renderer.onDidRenderAsync(() => {
162167
hoverContentsElement.className = 'hover-contents code-hover-contents';
163-
context.onContentsChanged();
168+
onFinishedRendering();
164169
}));
165170
const renderedContents = disposables.add(renderer.render(contents));
166171
hoverContentsElement.appendChild(renderedContents.element);
167-
context.fragment.appendChild(markdownHoverElement);
172+
container.appendChild(markdownHoverElement);
168173
}
169174
}
170175
return disposables;

src/vs/editor/contrib/unicodeHighlighter/browser/unicodeHighlighter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ export class UnicodeHighlighterHoverParticipant implements IEditorHoverParticipa
507507
}
508508

509509
public renderHoverParts(context: IEditorHoverRenderContext, hoverParts: MarkdownHover[]): IDisposable {
510-
return renderMarkdownHovers(context, hoverParts, this._editor, this._languageService, this._openerService);
510+
return renderMarkdownHovers(context.fragment, hoverParts, this._editor, this._languageService, this._openerService, context.onContentsChanged);
511511
}
512512
}
513513

0 commit comments

Comments
 (0)