@@ -26,6 +26,7 @@ export const enum AnchorPosition {
2626export interface IDelegate {
2727 getAnchor ( ) : HTMLElement | IAnchor ;
2828 render ( container : HTMLElement ) : IDisposable ;
29+ focus ?( ) : void ;
2930 layout ?( ) : void ;
3031 anchorAlignment ?: AnchorAlignment ; // default: left
3132 anchorPosition ?: AnchorPosition ; // default: below
@@ -165,6 +166,11 @@ export class ContextView extends Disposable {
165166
166167 // Layout
167168 this . doLayout ( ) ;
169+
170+ // Focus
171+ if ( this . delegate . focus ) {
172+ this . delegate . focus ( ) ;
173+ }
168174 }
169175
170176 public layout ( ) : void {
@@ -223,7 +229,7 @@ export class ContextView extends Disposable {
223229 const anchorPosition = this . delegate ! . anchorPosition || AnchorPosition . BELOW ;
224230 const anchorAlignment = this . delegate ! . anchorAlignment || AnchorAlignment . LEFT ;
225231
226- const verticalAnchor : ILayoutAnchor = { offset : around . top , size : around . height , position : anchorPosition === AnchorPosition . BELOW ? LayoutAnchorPosition . Before : LayoutAnchorPosition . After } ;
232+ const verticalAnchor : ILayoutAnchor = { offset : around . top - window . pageYOffset , size : around . height , position : anchorPosition === AnchorPosition . BELOW ? LayoutAnchorPosition . Before : LayoutAnchorPosition . After } ;
227233
228234 let horizontalAnchor : ILayoutAnchor ;
229235
@@ -233,7 +239,7 @@ export class ContextView extends Disposable {
233239 horizontalAnchor = { offset : around . left + around . width , size : 0 , position : LayoutAnchorPosition . After } ;
234240 }
235241
236- const top = layout ( window . innerHeight , viewSizeHeight , verticalAnchor ) ;
242+ const top = layout ( window . innerHeight , viewSizeHeight , verticalAnchor ) + window . pageYOffset ;
237243
238244 // if view intersects vertically with anchor, shift it horizontally
239245 if ( Range . intersects ( { start : top , end : top + viewSizeHeight } , { start : verticalAnchor . offset , end : verticalAnchor . offset + verticalAnchor . size } ) ) {
0 commit comments