From 6c61f43084d7d659665b460d85ccd18897e4088c Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 4 Jul 2019 10:49:39 +0200 Subject: [PATCH] history - allow to navigate with mouse buttons 3/4 --- src/vs/code/electron-main/window.ts | 17 ++++----- .../browser/workbench.contribution.ts | 8 ++++- src/vs/workbench/common/editor.ts | 1 + .../services/history/browser/history.ts | 36 ++++++++++++++++++- 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/vs/code/electron-main/window.ts b/src/vs/code/electron-main/window.ts index bbfe1bd21a0..3889550305b 100644 --- a/src/vs/code/electron-main/window.ts +++ b/src/vs/code/electron-main/window.ts @@ -373,9 +373,6 @@ export class CodeWindow extends Disposable implements ICodeWindow { } }); - // App commands support - this.registerNavigationListenerOn('app-command', 'browser-backward', 'browser-forward', false); - // Window Focus this._win.on('focus', () => { this._lastFocusTime = Date.now(); @@ -466,23 +463,23 @@ export class CodeWindow extends Disposable implements ICodeWindow { if (isMacintosh) { const config = this.configurationService.getValue(); if (config && config.workbench && config.workbench.editor && config.workbench.editor.swipeToNavigate) { - this.registerNavigationListenerOn('swipe', 'left', 'right', true); + this.registerSwipeListener(); } else { this._win.removeAllListeners('swipe'); } } } - private registerNavigationListenerOn(command: 'swipe' | 'app-command', back: 'left' | 'browser-backward', forward: 'right' | 'browser-forward', acrossEditors: boolean) { - this._win.on(command as 'swipe' /* | 'app-command' */, (e: Electron.Event, cmd: string) => { + private registerSwipeListener() { + this._win.on('swipe', (event: Electron.Event, cmd: string) => { if (!this.isReady) { return; // window must be ready } - if (cmd === back) { - this.send('vscode:runAction', { id: acrossEditors ? 'workbench.action.openPreviousRecentlyUsedEditor' : 'workbench.action.navigateBack', from: 'mouse' } as IRunActionInWindowRequest); - } else if (cmd === forward) { - this.send('vscode:runAction', { id: acrossEditors ? 'workbench.action.openNextRecentlyUsedEditor' : 'workbench.action.navigateForward', from: 'mouse' } as IRunActionInWindowRequest); + if (cmd === 'left') { + this.send('vscode:runAction', { id: 'workbench.action.openPreviousRecentlyUsedEditor', from: 'mouse' } as IRunActionInWindowRequest); + } else if (cmd === 'right') { + this.send('vscode:runAction', { id: 'workbench.action.openNextRecentlyUsedEditor', from: 'mouse' } as IRunActionInWindowRequest); } }); } diff --git a/src/vs/workbench/browser/workbench.contribution.ts b/src/vs/workbench/browser/workbench.contribution.ts index e13b2539b22..dc449eb18c5 100644 --- a/src/vs/workbench/browser/workbench.contribution.ts +++ b/src/vs/workbench/browser/workbench.contribution.ts @@ -111,7 +111,13 @@ import { isMacintosh, isWindows, isLinux, isWeb } from 'vs/base/common/platform' 'type': 'boolean', 'description': nls.localize('swipeToNavigate', "Navigate between open files using three-finger swipe horizontally."), 'default': false, - 'included': isMacintosh + 'included': isMacintosh && !isWeb + }, + 'workbench.editor.mouseBackForwardToNavigate': { + 'type': 'boolean', + 'description': nls.localize('mouseBackForwardToNavigate', "Navigate between open files using mouse buttons four and five if provided."), + 'default': true, + 'included': !isMacintosh }, 'workbench.editor.restoreViewState': { 'type': 'boolean', diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 3515bc8d82d..3286b47068e 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -987,6 +987,7 @@ interface IEditorPartConfiguration { closeEmptyGroups?: boolean; revealIfOpen?: boolean; swipeToNavigate?: boolean; + mouseBackForwardToNavigate?: boolean; labelFormat?: 'default' | 'short' | 'medium' | 'long'; restoreViewState?: boolean; } diff --git a/src/vs/workbench/services/history/browser/history.ts b/src/vs/workbench/services/history/browser/history.ts index c276acb6f6a..91e3136b50e 100644 --- a/src/vs/workbench/services/history/browser/history.ts +++ b/src/vs/workbench/services/history/browser/history.ts @@ -32,6 +32,7 @@ import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/cont import { coalesce } from 'vs/base/common/arrays'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { withNullAsUndefined } from 'vs/base/common/types'; +import { addDisposableListener, EventType, EventHelper } from 'vs/base/browser/dom'; /** * Stores the selection & view state of an editor and allows to compare it to other selection states. @@ -140,7 +141,7 @@ export class HistoryService extends Disposable implements IHistoryService { @IWindowService private readonly windowService: IWindowService, @IInstantiationService private readonly instantiationService: IInstantiationService, @IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService, - @IContextKeyService private readonly contextKeyService: IContextKeyService + @IContextKeyService private readonly contextKeyService: IContextKeyService, ) { super(); @@ -184,6 +185,39 @@ export class HistoryService extends Disposable implements IHistoryService { if (this.editorService.activeControl) { this.onActiveEditorChanged(); } + + // Mouse back/forward support + const mouseBackForwardSupportListener = this._register(new DisposableStore()); + const handleMouseBackForwardSupport = () => { + mouseBackForwardSupportListener.clear(); + + if (this.configurationService.getValue('workbench.editor.mouseBackForwardToNavigate')) { + mouseBackForwardSupportListener.add(addDisposableListener(this.layoutService.getWorkbenchElement(), EventType.MOUSE_DOWN, e => this.onMouseDown(e))); + } + }; + + this._register(this.configurationService.onDidChangeConfiguration(event => { + if (event.affectsConfiguration('workbench.editor.mouseBackForwardToNavigate')) { + handleMouseBackForwardSupport(); + } + })); + + handleMouseBackForwardSupport(); + } + + private onMouseDown(e: MouseEvent): void { + + // Support to navigate in history when mouse buttons 4/5 are pressed + switch (e.button) { + case 3: + EventHelper.stop(e); + this.back(); + break; + case 4: + EventHelper.stop(e); + this.forward(); + break; + } } private onActiveEditorChanged(): void { -- GitLab