6675c4b43a6327a744add197bf70c996ce01e110e49330466e627f11dfbc6a4829c14d4cee2f76e5429ea50c774d784801ea9f1ba440cd238e21936ddf5bf8 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. export class ResolvedKeybindingItem {
  6. constructor(resolvedKeybinding, command, commandArgs, when, isDefault, extensionId, isBuiltinExtension) {
  7. this._resolvedKeybindingItemBrand = undefined;
  8. this.resolvedKeybinding = resolvedKeybinding;
  9. this.keypressParts = resolvedKeybinding ? removeElementsAfterNulls(resolvedKeybinding.getDispatchParts()) : [];
  10. if (resolvedKeybinding && this.keypressParts.length === 0) {
  11. // handle possible single modifier chord keybindings
  12. this.keypressParts = removeElementsAfterNulls(resolvedKeybinding.getSingleModifierDispatchParts());
  13. }
  14. this.bubble = (command ? command.charCodeAt(0) === 94 /* CharCode.Caret */ : false);
  15. this.command = this.bubble ? command.substr(1) : command;
  16. this.commandArgs = commandArgs;
  17. this.when = when;
  18. this.isDefault = isDefault;
  19. this.extensionId = extensionId;
  20. this.isBuiltinExtension = isBuiltinExtension;
  21. }
  22. }
  23. export function removeElementsAfterNulls(arr) {
  24. const result = [];
  25. for (let i = 0, len = arr.length; i < len; i++) {
  26. const element = arr[i];
  27. if (!element) {
  28. // stop processing at first encountered null
  29. return result;
  30. }
  31. result.push(element);
  32. }
  33. return result;
  34. }