Skip to content

Commit 06fe616

Browse files
committed
Re-instate swipeToNavigate for Mac (fix #204812)
1 parent bb450f4 commit 06fe616

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

src/vs/platform/windows/electron-main/windowImpl.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ export interface IWindowCreationOptions {
5353
readonly isExtensionTestHost?: boolean;
5454
}
5555

56+
interface IWorkbenchEditorConfiguration {
57+
workbench?: {
58+
editor?: {
59+
swipeToNavigate?: boolean;
60+
};
61+
};
62+
}
63+
5664
interface ITouchBarSegment extends electron.SegmentedControlSegment {
5765
readonly id: string;
5866
}
@@ -1042,6 +1050,16 @@ export class CodeWindow extends BaseWindow implements ICodeWindow {
10421050

10431051
private onConfigurationUpdated(e?: IConfigurationChangeEvent): void {
10441052

1053+
// Swipe command support (macOS)
1054+
if (isMacintosh) {
1055+
const config = this.configurationService.getValue<IWorkbenchEditorConfiguration>();
1056+
if (config?.workbench?.editor?.swipeToNavigate) {
1057+
this.registerSwipeListener();
1058+
} else {
1059+
this._win.removeAllListeners('swipe');
1060+
}
1061+
}
1062+
10451063
// Menubar
10461064
if (!e || e.affectsConfiguration(MenuSettings.MenuBarVisibility)) {
10471065
const newMenuBarVisibility = this.getMenuBarVisibility();
@@ -1085,6 +1103,20 @@ export class CodeWindow extends BaseWindow implements ICodeWindow {
10851103
}
10861104
}
10871105

1106+
private registerSwipeListener() {
1107+
this._win.on('swipe', (event: Electron.Event, cmd: string) => {
1108+
if (!this.isReady) {
1109+
return; // window must be ready
1110+
}
1111+
1112+
if (cmd === 'left') {
1113+
this.send('vscode:runAction', { id: 'workbench.action.openPreviousRecentlyUsedEditor', from: 'mouse' });
1114+
} else if (cmd === 'right') {
1115+
this.send('vscode:runAction', { id: 'workbench.action.openNextRecentlyUsedEditor', from: 'mouse' });
1116+
}
1117+
});
1118+
}
1119+
10881120
addTabbedWindow(window: ICodeWindow): void {
10891121
if (isMacintosh && window.win) {
10901122
this._win.addTabbedWindow(window.win);

src/vs/workbench/browser/parts/editor/editor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const DEFAULT_EDITOR_PART_OPTIONS: IEditorPartOptions = {
6464
scrollToSwitchTabs: false,
6565
enablePreviewFromCodeNavigation: false,
6666
closeOnFileDelete: false,
67+
swipeToNavigate: false,
6768
mouseBackForwardToNavigate: true,
6869
restoreViewState: true,
6970
splitInGroupLayout: 'horizontal',
@@ -137,6 +138,7 @@ function validateEditorPartOptions(options: IEditorPartOptions): IEditorPartOpti
137138
'closeOnFileDelete': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['closeOnFileDelete']),
138139
'closeEmptyGroups': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['closeEmptyGroups']),
139140
'revealIfOpen': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['revealIfOpen']),
141+
'swipeToNavigate': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['swipeToNavigate']),
140142
'mouseBackForwardToNavigate': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['mouseBackForwardToNavigate']),
141143
'restoreViewState': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['restoreViewState']),
142144
'splitOnDragAndDrop': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['splitOnDragAndDrop']),

src/vs/workbench/browser/workbench.contribution.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
348348
'description': localize('revealIfOpen', "Controls whether an editor is revealed in any of the visible groups if opened. If disabled, an editor will prefer to open in the currently active editor group. If enabled, an already opened editor will be revealed instead of opened again in the currently active editor group. Note that there are some cases where this setting is ignored, such as when forcing an editor to open in a specific group or to the side of the currently active group."),
349349
'default': false
350350
},
351+
'workbench.editor.swipeToNavigate': {
352+
'type': 'boolean',
353+
'description': localize('swipeToNavigate', "Navigate between open files using three-finger swipe horizontally. Note that System Preferences > Trackpad > More Gestures must be set to 'Swipe with two or three fingers'."),
354+
'default': false,
355+
'included': isMacintosh && !isWeb
356+
},
351357
'workbench.editor.mouseBackForwardToNavigate': {
352358
'type': 'boolean',
353359
'description': localize('mouseBackForwardToNavigate', "Enables the use of mouse buttons four and five for commands 'Go Back' and 'Go Forward'."),

src/vs/workbench/common/editor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ interface IEditorPartConfiguration {
12541254
closeEmptyGroups?: boolean;
12551255
autoLockGroups?: Set<string>;
12561256
revealIfOpen?: boolean;
1257+
swipeToNavigate?: boolean;
12571258
mouseBackForwardToNavigate?: boolean;
12581259
labelFormat?: 'default' | 'short' | 'medium' | 'long';
12591260
restoreViewState?: boolean;

0 commit comments

Comments
 (0)