Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/vs/platform/windows/electron-main/windowImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,41 @@ export class CodeWindow extends BaseWindow implements ICodeWindow {

cb({ cancel: false, requestHeaders: Object.assign(details.requestHeaders, headers) });
});

this.registerSwipeGesture();
}
private registerSwipeGesture(): void {

const configurationKey = 'workbench.editor.swipeGestureRecognizer';
Comment on lines +743 to +745
Copy link
Preview

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration key string 'workbench.editor.swipeGestureRecognizer' is duplicated from workbench.contribution.ts. Consider defining this as a constant to avoid potential inconsistencies if the key name changes.

Copilot uses AI. Check for mistakes.

const swipeListener = this._register(new DisposableStore());

const swipeGestureRecognizer = (electronWindow: electron.BrowserWindow) => {

swipeListener.clear();
if (this.configurationService.getValue<boolean | undefined>(configurationKey) !== true) {
return;
}

const disposable = this._register(
Event.fromNodeEventEmitter(electronWindow, 'swipe',
(event: Electron.Event, direction: 'left' | 'right' | 'up' | 'down') => ({ event, direction }))((e) => {
this.sendWhenReady('vscode:runAction', CancellationToken.None, { id: '_workbench.triggerSwipeGesture', args: [e.direction] });

}));
Comment on lines +755 to +760
Copy link
Preview

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command ID '_workbench.triggerSwipeGesture' is duplicated from mainThreadWindow.ts. Consider defining this as a constant to maintain consistency and prevent typos.

Copilot uses AI. Check for mistakes.

swipeListener.add(disposable);

};

if (this.win !== null && isMacintosh) {
const win = this.win;
this._register(this.configurationService.onDidChangeConfiguration(event => {
if (event.affectsConfiguration(configurationKey)) {
swipeGestureRecognizer(win);
}
}));
swipeGestureRecognizer(win);
}

}

private marketplaceHeadersPromise: Promise<object> | undefined;
Expand Down
7 changes: 7 additions & 0 deletions src/vs/workbench/api/browser/mainThreadWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Event } from '../../../base/common/event.js';
import { DisposableStore } from '../../../base/common/lifecycle.js';
import { URI, UriComponents } from '../../../base/common/uri.js';
import { IOpenerService } from '../../../platform/opener/common/opener.js';
import { CommandsRegistry } from '../../../platform/commands/common/commands.js';
import { extHostNamedCustomer, IExtHostContext } from '../../services/extensions/common/extHostCustomers.js';
import { ExtHostContext, ExtHostWindowShape, IOpenUriOptions, MainContext, MainThreadWindowShape } from '../common/extHost.protocol.js';
import { IHostService } from '../../services/host/browser/host.js';
Expand All @@ -18,6 +19,7 @@ export class MainThreadWindow implements MainThreadWindowShape {

private readonly proxy: ExtHostWindowShape;
private readonly disposables = new DisposableStore();
private readonly commandRegistration;

constructor(
extHostContext: IExtHostContext,
Expand All @@ -31,10 +33,15 @@ export class MainThreadWindow implements MainThreadWindowShape {
(this.proxy.$onDidChangeWindowFocus, this.proxy, this.disposables);
userActivityService.onDidChangeIsActive(this.proxy.$onDidChangeWindowActive, this.proxy, this.disposables);
this.registerNativeHandle();

this.commandRegistration = CommandsRegistry.registerCommand('_workbench.triggerSwipeGesture', (accessor, direction: 'left' | 'right' | 'up' | 'down') => {
this.proxy.$onDidReceiveSwipeGesture(direction);
});
}

dispose(): void {
this.disposables.dispose();
this.commandRegistration.dispose();
}

registerNativeHandle(): void {
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I

// namespace: window
const window: typeof vscode.window = {
onDidReceiveSwipeGesture(listener, thisArg?, disposables?) {
return _asExtensionEvent(extHostWindow.onDidReceiveSwipeGesture)(listener, thisArg, disposables);
},
get activeTextEditor() {
return extHostEditors.getActiveTextEditor();
},
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,7 @@ export interface ExtHostWindowShape {
$onDidChangeWindowFocus(value: boolean): void;
$onDidChangeWindowActive(value: boolean): void;
$onDidChangeActiveNativeWindowHandle(handle: string | undefined): void;
$onDidReceiveSwipeGesture(direction: 'left' | 'right' | 'up' | 'down'): void;
}

export interface ExtHostLogLevelServiceShape {
Expand Down
7 changes: 7 additions & 0 deletions src/vs/workbench/api/common/extHostWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class ExtHostWindow implements ExtHostWindowShape {
private readonly _onDidChangeWindowState = new Emitter<WindowState>();
readonly onDidChangeWindowState: Event<WindowState> = this._onDidChangeWindowState.event;

private _onDidReceiveSwipeGesture = new Emitter<'left' | 'right' | 'up' | 'down'>();

readonly onDidReceiveSwipeGesture: Event<'left' | 'right' | 'up' | 'down'> = this._onDidReceiveSwipeGesture.event;
Comment on lines +29 to +31
Copy link
Preview

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The swipe direction type 'left' | 'right' | 'up' | 'down' is repeated multiple times. Consider defining this as a type alias to improve maintainability and consistency across the codebase.

Suggested change
private _onDidReceiveSwipeGesture = new Emitter<'left' | 'right' | 'up' | 'down'>();
readonly onDidReceiveSwipeGesture: Event<'left' | 'right' | 'up' | 'down'> = this._onDidReceiveSwipeGesture.event;
private _onDidReceiveSwipeGesture = new Emitter<SwipeDirection>();
readonly onDidReceiveSwipeGesture: Event<SwipeDirection> = this._onDidReceiveSwipeGesture.event;

Copilot uses AI. Check for mistakes.


private _nativeHandle: Uint8Array | undefined;
private _state = ExtHostWindow.InitialState;

Expand Down Expand Up @@ -56,6 +60,9 @@ export class ExtHostWindow implements ExtHostWindowShape {
this.onDidChangeWindowProperty('active', isActive);
});
}
$onDidReceiveSwipeGesture(direction: 'left' | 'right' | 'up' | 'down'): void {
this._onDidReceiveSwipeGesture.fire(direction);
}

get nativeHandle(): Uint8Array | undefined {
return this._nativeHandle;
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/browser/workbench.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
'description': localize('mouseBackForwardToNavigate', "Enables the use of mouse buttons four and five for commands 'Go Back' and 'Go Forward'."),
'default': true
},
'workbench.editor.swipeGestureRecognizer': {
'type': 'boolean',
'description': localize('swipeGestureRecognizer', "Register swipe gestures to be used in extensions."),
'default': false
},
'workbench.editor.navigationScope': {
'type': 'string',
'enum': ['default', 'editorGroup', 'editor'],
Expand Down
10 changes: 10 additions & 0 deletions src/vscode-dts/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11007,6 +11007,16 @@ declare module 'vscode' {
*/
export const onDidChangeActiveTextEditor: Event<TextEditor | undefined>;

/**
* Swipe gesture direction.
*/
export type SwipeGestureDirection = 'left' | 'right' | 'up' | 'down';

/**
* An {@link Event} which fires when a swipe gesture occurs.
*/
export const onDidReceiveSwipeGesture: Event<SwipeGestureDirection>;

/**
* An {@link Event} which fires when the array of {@link window.visibleTextEditors visible editors}
* has changed.
Expand Down