@@ -2,7 +2,7 @@ import '../missing-services'
22import { IEditorOverrideServices , StandaloneServices } from 'vs/editor/standalone/browser/standaloneServices'
33import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'
44import { WorkbenchKeybindingService } from 'vs/workbench/services/keybinding/browser/keybindingService'
5- import { IKeybindingService , IUserFriendlyKeybinding } from 'vs/platform/keybinding/common/keybinding'
5+ import { IKeybindingService , IKeyboardEvent , IUserFriendlyKeybinding } from 'vs/platform/keybinding/common/keybinding'
66import { VSBuffer } from 'vs/base/common/buffer'
77import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile'
88import { IKeyboardLayoutService } from 'vs/platform/keyboardLayout/common/keyboardLayout'
@@ -13,6 +13,14 @@ import { CommandService } from 'vs/workbench/services/commands/common/commandSer
1313import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem'
1414import { toDisposable } from 'vs/base/common/lifecycle'
1515import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver'
16+ import { IContextKeyService , IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey'
17+ import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'
18+ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'
19+ import { INotificationService } from 'vs/platform/notification/common/notification'
20+ import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile'
21+ import { IHostService } from 'vs/workbench/services/host/browser/host'
22+ import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'
23+ import { ILogService } from 'vs/platform/log/common/log'
1624import getFileServiceOverride from './files'
1725import { DynamicKeybindingService } from '../monaco'
1826import 'vs/workbench/browser/workbench.contribution'
@@ -26,6 +34,23 @@ async function updateUserKeybindings (keybindingsJson: string): Promise<void> {
2634class DynamicWorkbenchKeybindingService extends WorkbenchKeybindingService implements DynamicKeybindingService {
2735 private keybindingProviders : ( ( ) => ResolvedKeybindingItem [ ] ) [ ] = [ ]
2836
37+ constructor (
38+ private shouldUseGlobalKeybindings : ( ) => boolean ,
39+ @IContextKeyService contextKeyService : IContextKeyService ,
40+ @ICommandService commandService : ICommandService ,
41+ @ITelemetryService telemetryService : ITelemetryService ,
42+ @INotificationService notificationService : INotificationService ,
43+ @IUserDataProfileService userDataProfileService : IUserDataProfileService ,
44+ @IHostService hostService : IHostService ,
45+ @IExtensionService extensionService : IExtensionService ,
46+ @IFileService fileService : IFileService ,
47+ @IUriIdentityService uriIdentityService : IUriIdentityService ,
48+ @ILogService logService : ILogService ,
49+ @IKeyboardLayoutService keyboardLayoutService : IKeyboardLayoutService
50+ ) {
51+ super ( contextKeyService , commandService , telemetryService , notificationService , userDataProfileService , hostService , extensionService , fileService , uriIdentityService , logService , keyboardLayoutService )
52+ }
53+
2954 public registerKeybindingProvider ( provider : ( ) => ResolvedKeybindingItem [ ] ) {
3055 this . keybindingProviders . push ( provider )
3156 this . updateResolver ( )
@@ -43,15 +68,26 @@ class DynamicWorkbenchKeybindingService extends WorkbenchKeybindingService imple
4368 return super . _getResolver ( )
4469 }
4570
71+ protected override _dispatch ( e : IKeyboardEvent , target : IContextKeyServiceTarget ) : boolean {
72+ if ( ! this . shouldUseGlobalKeybindings ( ) ) {
73+ return false
74+ }
75+ return super . _dispatch ( e , target )
76+ }
77+
4678 protected override getUserKeybindingItems ( ) {
4779 return [ ...super . getUserKeybindingItems ( ) , ...this . keybindingProviders . flatMap ( provider => provider ( ) ) ]
4880 }
4981}
5082
51- export default function getServiceOverride ( ) : IEditorOverrideServices {
83+ interface KeybindingsProps {
84+ shouldUseGlobalKeybindings ?: ( ) => boolean
85+ }
86+
87+ export default function getServiceOverride ( { shouldUseGlobalKeybindings = ( ) => false } : KeybindingsProps = { } ) : IEditorOverrideServices {
5288 return {
5389 ...getFileServiceOverride ( ) ,
54- [ IKeybindingService . toString ( ) ] : new SyncDescriptor ( DynamicWorkbenchKeybindingService , [ ] , false ) ,
90+ [ IKeybindingService . toString ( ) ] : new SyncDescriptor ( DynamicWorkbenchKeybindingService , [ shouldUseGlobalKeybindings ] , false ) ,
5591 [ IKeyboardLayoutService . toString ( ) ] : new SyncDescriptor ( BrowserKeyboardLayoutService , undefined , true ) ,
5692 [ ICommandService . toString ( ) ] : new SyncDescriptor ( CommandService , [ ] , true )
5793 }
0 commit comments