diff --git a/scripts/vscode.patch b/scripts/vscode.patch index 529b78e3..e93fba06 100644 --- a/scripts/vscode.patch +++ b/scripts/vscode.patch @@ -397,7 +397,7 @@ index 23d547570e9..31dfb4fd8d4 100644 export * from 'vs/editor/editor.api'; diff --git a/src/vs/editor/standalone/browser/standaloneServices.ts b/src/vs/editor/standalone/browser/standaloneServices.ts -index 01f2c6987ac..a4853357178 100644 +index 01f2c6987ac..e3bf9b1e9e4 100644 --- a/src/vs/editor/standalone/browser/standaloneServices.ts +++ b/src/vs/editor/standalone/browser/standaloneServices.ts @@ -89,8 +89,6 @@ import { DefaultConfiguration } from 'vs/platform/configuration/common/configura @@ -409,7 +409,13 @@ index 01f2c6987ac..a4853357178 100644 import { ExtensionKind, IEnvironmentService, IExtensionHostDebugParams } from 'vs/platform/environment/common/environment'; class SimpleModel implements IResolvedTextEditorModel { -@@ -517,10 +515,14 @@ export class StandaloneKeybindingService extends AbstractKeybindingService { +@@ -512,15 +510,19 @@ export class StandaloneKeybindingService extends AbstractKeybindingService { + }); + } + +- private updateResolver(): void { ++ protected updateResolver(): void { + this._cachedResolver = null; this._onDidUpdateKeybindings.fire(); } diff --git a/src/monaco.ts b/src/monaco.ts index 78e2ea81..249a32b2 100644 --- a/src/monaco.ts +++ b/src/monaco.ts @@ -43,6 +43,8 @@ import { IKeybindingService, IKeyboardEvent } from 'vs/platform/keybinding/commo import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver' import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem' import { Keybinding, ResolvedKeybinding } from 'vs/base/common/keybindings' +import { Event } from 'vs/base/common/event' +import { Emitter } from 'monaco-editor' import { createInjectedClass } from './tools/injection' // Selectively comes from vs/workbench/contrib/codeEditor/browser/codeEditor.contribution.ts import 'vs/workbench/contrib/codeEditor/browser/workbenchReferenceSearch' @@ -182,8 +184,13 @@ export async function createModelReference (resource: URI, content?: string): Pr return (await StandaloneServices.get(ITextModelService).createModelReference(resource)) as IReference } +export interface KeybindingProvider { + provideKeybindings (): ResolvedKeybindingItem[] + onDidChangeKeybindings: Event +} + export interface DynamicKeybindingService extends IKeybindingService { - registerKeybindingProvider (provider: () => ResolvedKeybindingItem[]): IDisposable + registerKeybindingProvider (provider: KeybindingProvider): IDisposable _getResolver(): KeybindingResolver } @@ -195,6 +202,7 @@ function isDynamicKeybindingService (keybindingService: IKeybindingService) { // This class use useful so editor.addAction and editor.addCommand still work // Monaco do an `instanceof` on the KeybindingService so we need it to extends `StandaloneKeybindingService` class DelegateStandaloneKeybindingService extends StandaloneKeybindingService { + private _onDidChangeKeybindings = new Emitter() constructor ( private delegate: DynamicKeybindingService, @IContextKeyService contextKeyService: IContextKeyService, @@ -206,13 +214,23 @@ class DelegateStandaloneKeybindingService extends StandaloneKeybindingService { ) { super(contextKeyService, commandService, telemetryService, notificationService, logService, codeEditorService) - this._register(delegate.registerKeybindingProvider(() => this.getUserKeybindingItems())) + this._register(delegate.registerKeybindingProvider({ + provideKeybindings: () => { + return this.getUserKeybindingItems() + }, + onDidChangeKeybindings: this._onDidChangeKeybindings.event + })) } protected override _getResolver (): KeybindingResolver { return this.delegate._getResolver() } + protected override updateResolver (): void { + super.updateResolver() + this._onDidChangeKeybindings.fire() + } + override resolveKeyboardEvent (keyboardEvent: IKeyboardEvent): ResolvedKeybinding { return this.delegate.resolveKeyboardEvent(keyboardEvent) } diff --git a/src/service-override/keybindings.ts b/src/service-override/keybindings.ts index c766e06b..a900aa2a 100644 --- a/src/service-override/keybindings.ts +++ b/src/service-override/keybindings.ts @@ -9,7 +9,6 @@ import { BrowserKeyboardLayoutService } from 'vs/workbench/services/keybinding/b import { IFileService, IFileWriteOptions } from 'vs/platform/files/common/files' import { ICommandService } from 'vs/platform/commands/common/commands' import { CommandService } from 'vs/workbench/services/commands/common/commandService' -import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem' import { toDisposable } from 'vs/base/common/lifecycle' import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingResolver' import { IContextKeyService, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey' @@ -24,7 +23,7 @@ import { WorkbenchContextKeysHandler } from 'vs/workbench/browser/contextkeys' import { Schemas } from 'vs/base/common/network' import { URI } from 'vs/base/common/uri' import getFileServiceOverride, { initFile } from './files' -import { DynamicKeybindingService } from '../monaco' +import { DisposableStore, DynamicKeybindingService, KeybindingProvider } from '../monaco' import { onRenderWorkbench } from '../lifecycle' import { IInstantiationService } from '../services' import 'vs/workbench/browser/workbench.contribution' @@ -50,7 +49,7 @@ async function updateUserKeybindings (keybindingsJson: string): Promise { } class DynamicWorkbenchKeybindingService extends WorkbenchKeybindingService implements DynamicKeybindingService { - private keybindingProviders: (() => ResolvedKeybindingItem[])[] = [] + private keybindingProviders: KeybindingProvider[] = [] constructor ( private shouldUseGlobalKeybindings: () => boolean, @@ -69,17 +68,24 @@ class DynamicWorkbenchKeybindingService extends WorkbenchKeybindingService imple super(contextKeyService, commandService, telemetryService, notificationService, userDataProfileService, hostService, extensionService, fileService, uriIdentityService, logService, keyboardLayoutService) } - public registerKeybindingProvider (provider: () => ResolvedKeybindingItem[]) { + public registerKeybindingProvider (provider: KeybindingProvider) { this.keybindingProviders.push(provider) this.updateResolver() - return toDisposable(() => { + const store = new DisposableStore() + store.add(provider.onDidChangeKeybindings(() => { + this.updateResolver() + })) + + store.add(toDisposable(() => { const idx = this.keybindingProviders.indexOf(provider) if (idx >= 0) { this.keybindingProviders.splice(idx, 1) this.updateResolver() } - }) + })) + + return store } public override _getResolver (): KeybindingResolver { @@ -94,7 +100,7 @@ class DynamicWorkbenchKeybindingService extends WorkbenchKeybindingService imple } protected override getUserKeybindingItems () { - return [...super.getUserKeybindingItems(), ...this.keybindingProviders.flatMap(provider => provider())] + return [...super.getUserKeybindingItems(), ...this.keybindingProviders.flatMap(provider => provider.provideKeybindings())] } }