mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 12:04:04 +01:00
refactor keybindings merge
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { parse } from 'vs/base/common/json';
|
||||
import { IUserFriendlyKeybinding, IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IUserKeybindingsResolverService } from 'vs/platform/userDataSync/common/userDataSync';
|
||||
import { IStringDictionary } from 'vs/base/common/collections';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
|
||||
export class UserKeybindingsResolverService implements IUserKeybindingsResolverService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
constructor(
|
||||
@IKeybindingService private readonly keybindingsService: IKeybindingService
|
||||
) { }
|
||||
|
||||
public async resolveUserKeybindings(localContent: string, remoteContent: string, baseContent: string | null): Promise<IStringDictionary<string>> {
|
||||
const local = <IUserFriendlyKeybinding[]>parse(localContent);
|
||||
const remote = <IUserFriendlyKeybinding[]>parse(remoteContent);
|
||||
const base = baseContent ? <IUserFriendlyKeybinding[]>parse(baseContent) : null;
|
||||
const keys: IStringDictionary<string> = {};
|
||||
for (const keybinding of [...local, ...remote, ...(base || [])]) {
|
||||
keys[keybinding.key] = this.keybindingsService.resolveUserBinding(keybinding.key).map(part => part.getUserSettingsLabel()).join(' ');
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(IUserKeybindingsResolverService, UserKeybindingsResolverService);
|
||||
Reference in New Issue
Block a user