Skip to content

Commit 5ed7107

Browse files
authored
Re-instate swipeToNavigate for Mac (fix #204812) (#276360)
* Re-instate swipeToNavigate for Mac (fix #204812) * feedback
1 parent 4c60b3c commit 5ed7107

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,16 @@ export class CodeWindow extends BaseWindow implements ICodeWindow {
10421042

10431043
private onConfigurationUpdated(e?: IConfigurationChangeEvent): void {
10441044

1045+
// Swipe command support (macOS)
1046+
if (isMacintosh && (!e || e.affectsConfiguration('workbench.editor.swipeToNavigate'))) {
1047+
const swipeToNavigate = this.configurationService.getValue<boolean>('workbench.editor.swipeToNavigate');
1048+
if (swipeToNavigate) {
1049+
this.registerSwipeListener();
1050+
} else {
1051+
this.swipeListenerDisposable.clear();
1052+
}
1053+
}
1054+
10451055
// Menubar
10461056
if (!e || e.affectsConfiguration(MenuSettings.MenuBarVisibility)) {
10471057
const newMenuBarVisibility = this.getMenuBarVisibility();
@@ -1085,6 +1095,22 @@ export class CodeWindow extends BaseWindow implements ICodeWindow {
10851095
}
10861096
}
10871097

1098+
private readonly swipeListenerDisposable = this._register(new MutableDisposable());
1099+
1100+
private registerSwipeListener(): void {
1101+
this.swipeListenerDisposable.value = Event.fromNodeEventEmitter<string>(this._win, 'swipe', (event: Electron.Event, cmd: string) => cmd)(cmd => {
1102+
if (!this.isReady) {
1103+
return; // window must be ready
1104+
}
1105+
1106+
if (cmd === 'left') {
1107+
this.send('vscode:runAction', { id: 'workbench.action.openPreviousRecentlyUsedEditor', from: 'mouse' });
1108+
} else if (cmd === 'right') {
1109+
this.send('vscode:runAction', { id: 'workbench.action.openNextRecentlyUsedEditor', from: 'mouse' });
1110+
}
1111+
});
1112+
}
1113+
10881114
addTabbedWindow(window: ICodeWindow): void {
10891115
if (isMacintosh && window.win) {
10901116
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)