提交 6c61f430 编写于 作者: B Benjamin Pasero

history - allow to navigate with mouse buttons 3/4

上级 befa9e6f
......@@ -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<IWorkbenchEditorConfiguration>();
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);
}
});
}
......
......@@ -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',
......
......@@ -987,6 +987,7 @@ interface IEditorPartConfiguration {
closeEmptyGroups?: boolean;
revealIfOpen?: boolean;
swipeToNavigate?: boolean;
mouseBackForwardToNavigate?: boolean;
labelFormat?: 'default' | 'short' | 'medium' | 'long';
restoreViewState?: boolean;
}
......
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册