Skip to content

Commit 92402b8

Browse files
committed
1 parent 94f5a49 commit 92402b8

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/vs/base/browser/ui/contextview/contextview.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const enum AnchorPosition {
2626
export 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 })) {

src/vs/editor/contrib/contextmenu/contextmenu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class ContextMenuController implements IEditorContribution {
9595
// Unless the user triggerd the context menu through Shift+F10, use the mouse position as menu position
9696
let forcedPosition: IPosition;
9797
if (e.target.type !== MouseTargetType.TEXTAREA) {
98-
forcedPosition = { x: e.event.posx, y: e.event.posy + 1 };
98+
forcedPosition = { x: e.event.posx + 2, y: e.event.posy + 1 };
9999
}
100100

101101
// Show the context menu

src/vs/platform/contextview/browser/contextMenuHandler.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export class ContextMenuHandler {
5757

5858
this.focusToReturn = document.activeElement as HTMLElement;
5959

60+
let menu: Menu | undefined;
61+
6062
this.contextViewService.showContextView({
6163
getAnchor: () => delegate.getAnchor(),
6264
canRelayout: false,
@@ -77,7 +79,7 @@ export class ContextMenuHandler {
7779
actionRunner.onDidBeforeRun(this.onActionRun, this, menuDisposables);
7880
actionRunner.onDidRun(this.onDidActionRun, this, menuDisposables);
7981

80-
const menu = new Menu(container, actions, {
82+
menu = new Menu(container, actions, {
8183
actionItemProvider: delegate.getActionItem,
8284
context: delegate.getActionsContext ? delegate.getActionsContext() : null,
8385
actionRunner,
@@ -90,11 +92,13 @@ export class ContextMenuHandler {
9092
menu.onDidBlur(() => this.contextViewService.hideContextView(true), null, menuDisposables);
9193
domEvent(window, EventType.BLUR)(() => { this.contextViewService.hideContextView(true); }, null, menuDisposables);
9294

93-
menu.focus(!!delegate.autoSelectFirstItem);
94-
9595
return combinedDisposable([...menuDisposables, menu]);
9696
},
9797

98+
focus: () => {
99+
menu.focus(!!delegate.autoSelectFirstItem);
100+
},
101+
98102
onHide: (didCancel?: boolean) => {
99103
if (delegate.onHide) {
100104
delegate.onHide(didCancel);

src/vs/platform/contextview/browser/contextView.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface IContextViewDelegate {
2929
render(container: HTMLElement): IDisposable;
3030
onDOMEvent?(e: any, activeElement: HTMLElement): void;
3131
onHide?(data?: any): void;
32+
focus?(): void;
3233
anchorAlignment?: AnchorAlignment;
3334
}
3435

0 commit comments

Comments
 (0)