resolvedKeybindingItem.js 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 /* 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. let 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. }