Skip to content

Commit

Permalink
fix #133622
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Nov 5, 2021
1 parent 05a2f28 commit 2499f31
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/suggest/suggestWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ export class SuggestWidget implements IDisposable {

private _positionDetails(): void {
if (this._isDetailsVisible()) {
this._details.placeAtAnchor(this.element.domNode);
this._details.placeAtAnchor(this.element.domNode, this._contentWidget.getPosition()?.preference[0] === ContentWidgetPositionPreference.BELOW);
}
}

Expand Down
30 changes: 21 additions & 9 deletions src/vs/editor/contrib/suggest/suggestWidgetDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export class SuggestDetailsOverlay implements IOverlayWidget {

private _added: boolean = false;
private _anchorBox?: dom.IDomNodePagePosition;
private _preferAlignAtTop: boolean = true;
private _userSize?: dom.Dimension;
private _topLeft?: TopLeftPosition;

Expand Down Expand Up @@ -315,7 +316,7 @@ export class SuggestDetailsOverlay implements IOverlayWidget {

this._disposables.add(this.widget.onDidChangeContents(() => {
if (this._anchorBox) {
this._placeAtAnchor(this._anchorBox, this._userSize ?? this.widget.size);
this._placeAtAnchor(this._anchorBox, this._userSize ?? this.widget.size, this._preferAlignAtTop);
}
}));
}
Expand Down Expand Up @@ -361,13 +362,14 @@ export class SuggestDetailsOverlay implements IOverlayWidget {
}
}

placeAtAnchor(anchor: HTMLElement) {
placeAtAnchor(anchor: HTMLElement, preferAlignAtTop: boolean) {
const anchorBox = dom.getDomNodePagePosition(anchor);
this._anchorBox = anchorBox;
this._placeAtAnchor(this._anchorBox, this._userSize ?? this.widget.size);
this._preferAlignAtTop = preferAlignAtTop;
this._placeAtAnchor(this._anchorBox, this._userSize ?? this.widget.size, preferAlignAtTop);
}

_placeAtAnchor(anchorBox: dom.IDomNodePagePosition, size: dom.Dimension) {
_placeAtAnchor(anchorBox: dom.IDomNodePagePosition, size: dom.Dimension, preferAlignAtTop: boolean) {
const bodyBox = dom.getClientArea(document.body);

const info = this.widget.getLayoutInfo();
Expand Down Expand Up @@ -416,12 +418,22 @@ export class SuggestDetailsOverlay implements IOverlayWidget {
height = maxHeight;
}
let maxSize: dom.Dimension;
if (height <= placement.maxSizeTop.height) {
alignAtTop = true;
maxSize = placement.maxSizeTop;
if (preferAlignAtTop) {
if (height <= placement.maxSizeTop.height) {
alignAtTop = true;
maxSize = placement.maxSizeTop;
} else {
alignAtTop = false;
maxSize = placement.maxSizeBottom;
}
} else {
alignAtTop = false;
maxSize = placement.maxSizeBottom;
if (height <= placement.maxSizeBottom.height) {
alignAtTop = false;
maxSize = placement.maxSizeBottom;
} else {
alignAtTop = true;
maxSize = placement.maxSizeTop;
}
}

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

0 comments on commit 2499f31

Please sign in to comment.