Skip to content

Commit 2499f31

Browse files
committed
1 parent 05a2f28 commit 2499f31

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/vs/editor/contrib/suggest/suggestWidget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ export class SuggestWidget implements IDisposable {
825825

826826
private _positionDetails(): void {
827827
if (this._isDetailsVisible()) {
828-
this._details.placeAtAnchor(this.element.domNode);
828+
this._details.placeAtAnchor(this.element.domNode, this._contentWidget.getPosition()?.preference[0] === ContentWidgetPositionPreference.BELOW);
829829
}
830830
}
831831

src/vs/editor/contrib/suggest/suggestWidgetDetails.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export class SuggestDetailsOverlay implements IOverlayWidget {
262262

263263
private _added: boolean = false;
264264
private _anchorBox?: dom.IDomNodePagePosition;
265+
private _preferAlignAtTop: boolean = true;
265266
private _userSize?: dom.Dimension;
266267
private _topLeft?: TopLeftPosition;
267268

@@ -315,7 +316,7 @@ export class SuggestDetailsOverlay implements IOverlayWidget {
315316

316317
this._disposables.add(this.widget.onDidChangeContents(() => {
317318
if (this._anchorBox) {
318-
this._placeAtAnchor(this._anchorBox, this._userSize ?? this.widget.size);
319+
this._placeAtAnchor(this._anchorBox, this._userSize ?? this.widget.size, this._preferAlignAtTop);
319320
}
320321
}));
321322
}
@@ -361,13 +362,14 @@ export class SuggestDetailsOverlay implements IOverlayWidget {
361362
}
362363
}
363364

364-
placeAtAnchor(anchor: HTMLElement) {
365+
placeAtAnchor(anchor: HTMLElement, preferAlignAtTop: boolean) {
365366
const anchorBox = dom.getDomNodePagePosition(anchor);
366367
this._anchorBox = anchorBox;
367-
this._placeAtAnchor(this._anchorBox, this._userSize ?? this.widget.size);
368+
this._preferAlignAtTop = preferAlignAtTop;
369+
this._placeAtAnchor(this._anchorBox, this._userSize ?? this.widget.size, preferAlignAtTop);
368370
}
369371

370-
_placeAtAnchor(anchorBox: dom.IDomNodePagePosition, size: dom.Dimension) {
372+
_placeAtAnchor(anchorBox: dom.IDomNodePagePosition, size: dom.Dimension, preferAlignAtTop: boolean) {
371373
const bodyBox = dom.getClientArea(document.body);
372374

373375
const info = this.widget.getLayoutInfo();
@@ -416,12 +418,22 @@ export class SuggestDetailsOverlay implements IOverlayWidget {
416418
height = maxHeight;
417419
}
418420
let maxSize: dom.Dimension;
419-
if (height <= placement.maxSizeTop.height) {
420-
alignAtTop = true;
421-
maxSize = placement.maxSizeTop;
421+
if (preferAlignAtTop) {
422+
if (height <= placement.maxSizeTop.height) {
423+
alignAtTop = true;
424+
maxSize = placement.maxSizeTop;
425+
} else {
426+
alignAtTop = false;
427+
maxSize = placement.maxSizeBottom;
428+
}
422429
} else {
423-
alignAtTop = false;
424-
maxSize = placement.maxSizeBottom;
430+
if (height <= placement.maxSizeBottom.height) {
431+
alignAtTop = false;
432+
maxSize = placement.maxSizeBottom;
433+
} else {
434+
alignAtTop = true;
435+
maxSize = placement.maxSizeTop;
436+
}
425437
}
426438

427439
this._applyTopLeft({ left: placement.left, top: alignAtTop ? placement.top : bottom - height });

0 commit comments

Comments
 (0)