Skip to content

Commit

Permalink
Prevent back/forward gestures on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Sep 16, 2019
1 parent 449b87d commit aa1e292
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/vs/base/browser/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ class DomListener implements IDisposable {
private _handler: (e: any) => void;
private _node: Element | Window | Document;
private readonly _type: string;
private readonly _useCapture: boolean;
private readonly _options: boolean | AddEventListenerOptions;

constructor(node: Element | Window | Document, type: string, handler: (e: any) => void, useCapture?: boolean) {
constructor(node: Element | Window | Document, type: string, handler: (e: any) => void, options?: boolean | AddEventListenerOptions) {
this._node = node;
this._type = type;
this._handler = handler;
this._useCapture = (useCapture || false);
this._node.addEventListener(this._type, this._handler, this._useCapture);
this._options = (options || false);
this._node.addEventListener(this._type, this._handler, this._options);
}

public dispose(): void {
Expand All @@ -221,7 +221,7 @@ class DomListener implements IDisposable {
return;
}

this._node.removeEventListener(this._type, this._handler, this._useCapture);
this._node.removeEventListener(this._type, this._handler, this._options);

// Prevent leakers from holding on to the dom or handler func
this._node = null!;
Expand All @@ -231,7 +231,8 @@ class DomListener implements IDisposable {

export function addDisposableListener<K extends keyof GlobalEventHandlersEventMap>(node: Element | Window | Document, type: K, handler: (event: GlobalEventHandlersEventMap[K]) => void, useCapture?: boolean): IDisposable;
export function addDisposableListener(node: Element | Window | Document, type: string, handler: (event: any) => void, useCapture?: boolean): IDisposable;
export function addDisposableListener(node: Element | Window | Document, type: string, handler: (event: any) => void, useCapture?: boolean): IDisposable {
export function addDisposableListener(node: Element | Window | Document, type: string, handler: (event: any) => void, useCapture: AddEventListenerOptions): IDisposable;
export function addDisposableListener(node: Element | Window | Document, type: string, handler: (event: any) => void, useCapture?: boolean | AddEventListenerOptions): IDisposable {
return new DomListener(node, type, handler, useCapture);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export class EditorScrollbar extends ViewPart {
const fastScrollSensitivity = options.get(EditorOption.fastScrollSensitivity);

const scrollbarOptions: ScrollableElementCreationOptions = {
alwaysConsumeMouseWheel: true,
listenOnDomNode: viewDomNode.domNode,
className: 'editor-scrollable' + ' ' + getThemeTypeSelector(context.theme.type),
useShadows: false,
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/browser/web.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class CodeRendererMain extends Disposable {
// Layout
this._register(addDisposableListener(window, EventType.RESIZE, () => workbench.layout()));

// Prevent the back/forward gestures in macOS
this._register(addDisposableListener(this.domElement, EventType.WHEEL, (e) => {
e.preventDefault();
}, { passive: false }));

// Workbench Lifecycle
this._register(workbench.onBeforeShutdown(event => {
if (services.storageService.hasPendingUpdate) {
Expand Down

0 comments on commit aa1e292

Please sign in to comment.