This commit is contained in:
Joao Moreno
2018-11-21 16:15:23 +01:00
parent 94f5a49633
commit 92402b8e53
4 changed files with 17 additions and 6 deletions

View File

@@ -26,6 +26,7 @@ export const enum AnchorPosition {
export interface IDelegate {
getAnchor(): HTMLElement | IAnchor;
render(container: HTMLElement): IDisposable;
focus?(): void;
layout?(): void;
anchorAlignment?: AnchorAlignment; // default: left
anchorPosition?: AnchorPosition; // default: below
@@ -165,6 +166,11 @@ export class ContextView extends Disposable {
// Layout
this.doLayout();
// Focus
if (this.delegate.focus) {
this.delegate.focus();
}
}
public layout(): void {
@@ -223,7 +229,7 @@ export class ContextView extends Disposable {
const anchorPosition = this.delegate!.anchorPosition || AnchorPosition.BELOW;
const anchorAlignment = this.delegate!.anchorAlignment || AnchorAlignment.LEFT;
const verticalAnchor: ILayoutAnchor = { offset: around.top, size: around.height, position: anchorPosition === AnchorPosition.BELOW ? LayoutAnchorPosition.Before : LayoutAnchorPosition.After };
const verticalAnchor: ILayoutAnchor = { offset: around.top - window.pageYOffset, size: around.height, position: anchorPosition === AnchorPosition.BELOW ? LayoutAnchorPosition.Before : LayoutAnchorPosition.After };
let horizontalAnchor: ILayoutAnchor;
@@ -233,7 +239,7 @@ export class ContextView extends Disposable {
horizontalAnchor = { offset: around.left + around.width, size: 0, position: LayoutAnchorPosition.After };
}
const top = layout(window.innerHeight, viewSizeHeight, verticalAnchor);
const top = layout(window.innerHeight, viewSizeHeight, verticalAnchor) + window.pageYOffset;
// if view intersects vertically with anchor, shift it horizontally
if (Range.intersects({ start: top, end: top + viewSizeHeight }, { start: verticalAnchor.offset, end: verticalAnchor.offset + verticalAnchor.size })) {