提交 2e0c53de 编写于 作者: D Daniel Imms

Add forcePosition hover option, restrict extension hovers

Fixes #129546
上级 9ef29de2
......@@ -400,6 +400,7 @@ export class ExtensionHoverWidget extends ExtensionWidget {
return this.hoverService.showHover({
...options,
hoverPosition: this.options.position(),
forcePosition: true,
additionalClasses: ['extension-hover']
});
},
......
......@@ -82,11 +82,18 @@ export interface IHoverOptions {
hideOnHover?: boolean;
/**
* Position of the hover. Default is to show above the target.
* It will be ignored if there is not enough room to layout the hover in the specified position.
* Position of the hover. The default is to show above the target. This option will be ignored
* if there is not enough room to layout the hover in the specified position, unless the
* forcePosition option is set.
*/
hoverPosition?: HoverPosition;
/**
* Force the hover position, reducing the size of the hover instead of adjusting the hover
* position.
*/
forcePosition?: boolean
/**
* Whether to show the hover pointer
*/
......
......@@ -48,6 +48,7 @@ export class HoverWidget extends Widget {
private _isDisposed: boolean = false;
private _hoverPosition: HoverPosition;
private _forcePosition: boolean = false;
private _x: number = 0;
private _y: number = 0;
......@@ -88,6 +89,9 @@ export class HoverWidget extends Widget {
if (options.additionalClasses) {
this._hover.containerDomNode.classList.add(...options.additionalClasses);
}
if (options.forcePosition) {
this._forcePosition = true;
}
this._hoverPosition = options.hoverPosition ?? HoverPosition.ABOVE;
......@@ -327,6 +331,17 @@ export class HoverWidget extends Widget {
return;
}
// When force position is enabled, restrict max width
if (this._forcePosition) {
const padding = (this._hoverPointer ? Constants.PointerSize : 0) + Constants.HoverBorderWidth;
if (this._hoverPosition === HoverPosition.RIGHT) {
this._hover.containerDomNode.style.maxWidth = `${document.documentElement.clientWidth - target.right - padding}px`;
} else if (this._hoverPosition === HoverPosition.LEFT) {
this._hover.containerDomNode.style.maxWidth = `${target.left - padding}px`;
}
return;
}
// Position hover on right to target
if (this._hoverPosition === HoverPosition.RIGHT) {
// Hover on the right is going beyond window.
......@@ -350,6 +365,17 @@ export class HoverWidget extends Widget {
return;
}
// When force position is enabled, restrict max height
if (this._forcePosition) {
const padding = (this._hoverPointer ? Constants.PointerSize : 0) + Constants.HoverBorderWidth;
if (this._hoverPosition === HoverPosition.ABOVE) {
this._hover.containerDomNode.style.maxHeight = `${target.top - padding}px`;
} else if (this._hoverPosition === HoverPosition.BELOW) {
this._hover.containerDomNode.style.maxHeight = `${window.innerHeight - target.bottom - padding}px`;
}
return;
}
// Position hover on top of the target
if (this._hoverPosition === HoverPosition.ABOVE) {
// Hover on top is going beyond window
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册