71db46e97db8827e66602b29851e89e6f3525520c83e76119013a9f4a627c50018fc76f8894267bd6525b1d9d26fae57018cde7b8c611d5a034f5e80098f76 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  6. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  9. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10. };
  11. var __param = (this && this.__param) || function (paramIndex, decorator) {
  12. return function (target, key) { decorator(target, key, paramIndex); }
  13. };
  14. import { FindInput } from '../../../base/browser/ui/findinput/findInput.js';
  15. import { ReplaceInput } from '../../../base/browser/ui/findinput/replaceInput.js';
  16. import { ContextKeyExpr, IContextKeyService, RawContextKey } from '../../contextkey/common/contextkey.js';
  17. import { KeybindingsRegistry } from '../../keybinding/common/keybindingsRegistry.js';
  18. import { localize } from '../../../nls.js';
  19. import { DisposableStore, toDisposable } from '../../../base/common/lifecycle.js';
  20. export const historyNavigationVisible = new RawContextKey('suggestWidgetVisible', false, localize('suggestWidgetVisible', "Whether suggestion are visible"));
  21. const HistoryNavigationWidgetFocusContext = 'historyNavigationWidgetFocus';
  22. const HistoryNavigationForwardsEnablementContext = 'historyNavigationForwardsEnabled';
  23. const HistoryNavigationBackwardsEnablementContext = 'historyNavigationBackwardsEnabled';
  24. let lastFocusedWidget = undefined;
  25. const widgets = [];
  26. export function registerAndCreateHistoryNavigationContext(contextKeyService, widget) {
  27. if (widgets.includes(widget)) {
  28. throw new Error('Cannot register the same widget multiple times');
  29. }
  30. widgets.push(widget);
  31. const disposableStore = new DisposableStore();
  32. const scopedContextKeyService = disposableStore.add(contextKeyService.createScoped(widget.element));
  33. const historyNavigationWidgetFocus = new RawContextKey(HistoryNavigationWidgetFocusContext, false).bindTo(scopedContextKeyService);
  34. const historyNavigationForwardsEnablement = new RawContextKey(HistoryNavigationForwardsEnablementContext, true).bindTo(scopedContextKeyService);
  35. const historyNavigationBackwardsEnablement = new RawContextKey(HistoryNavigationBackwardsEnablementContext, true).bindTo(scopedContextKeyService);
  36. const onDidFocus = () => {
  37. historyNavigationWidgetFocus.set(true);
  38. lastFocusedWidget = widget;
  39. };
  40. const onDidBlur = () => {
  41. historyNavigationWidgetFocus.set(false);
  42. if (lastFocusedWidget === widget) {
  43. lastFocusedWidget = undefined;
  44. }
  45. };
  46. // Check for currently being focused
  47. if (widget.element === document.activeElement) {
  48. onDidFocus();
  49. }
  50. disposableStore.add(widget.onDidFocus(() => onDidFocus()));
  51. disposableStore.add(widget.onDidBlur(() => onDidBlur()));
  52. disposableStore.add(toDisposable(() => {
  53. widgets.splice(widgets.indexOf(widget), 1);
  54. onDidBlur();
  55. }));
  56. return {
  57. scopedContextKeyService,
  58. historyNavigationForwardsEnablement,
  59. historyNavigationBackwardsEnablement,
  60. dispose() {
  61. disposableStore.dispose();
  62. }
  63. };
  64. }
  65. let ContextScopedFindInput = class ContextScopedFindInput extends FindInput {
  66. constructor(container, contextViewProvider, options, contextKeyService, showFindOptions = false) {
  67. super(container, contextViewProvider, showFindOptions, options);
  68. this._register(registerAndCreateHistoryNavigationContext(contextKeyService, this.inputBox));
  69. }
  70. };
  71. ContextScopedFindInput = __decorate([
  72. __param(3, IContextKeyService)
  73. ], ContextScopedFindInput);
  74. export { ContextScopedFindInput };
  75. let ContextScopedReplaceInput = class ContextScopedReplaceInput extends ReplaceInput {
  76. constructor(container, contextViewProvider, options, contextKeyService, showReplaceOptions = false) {
  77. super(container, contextViewProvider, showReplaceOptions, options);
  78. this._register(registerAndCreateHistoryNavigationContext(contextKeyService, this.inputBox));
  79. }
  80. };
  81. ContextScopedReplaceInput = __decorate([
  82. __param(3, IContextKeyService)
  83. ], ContextScopedReplaceInput);
  84. export { ContextScopedReplaceInput };
  85. KeybindingsRegistry.registerCommandAndKeybindingRule({
  86. id: 'history.showPrevious',
  87. weight: 200 /* KeybindingWeight.WorkbenchContrib */,
  88. when: ContextKeyExpr.and(ContextKeyExpr.has(HistoryNavigationWidgetFocusContext), ContextKeyExpr.equals(HistoryNavigationBackwardsEnablementContext, true), historyNavigationVisible.isEqualTo(false)),
  89. primary: 16 /* KeyCode.UpArrow */,
  90. secondary: [512 /* KeyMod.Alt */ | 16 /* KeyCode.UpArrow */],
  91. handler: (accessor) => {
  92. if (lastFocusedWidget) {
  93. lastFocusedWidget.showPreviousValue();
  94. }
  95. }
  96. });
  97. KeybindingsRegistry.registerCommandAndKeybindingRule({
  98. id: 'history.showNext',
  99. weight: 200 /* KeybindingWeight.WorkbenchContrib */,
  100. when: ContextKeyExpr.and(ContextKeyExpr.has(HistoryNavigationWidgetFocusContext), ContextKeyExpr.equals(HistoryNavigationForwardsEnablementContext, true), historyNavigationVisible.isEqualTo(false)),
  101. primary: 18 /* KeyCode.DownArrow */,
  102. secondary: [512 /* KeyMod.Alt */ | 18 /* KeyCode.DownArrow */],
  103. handler: (accessor) => {
  104. if (lastFocusedWidget) {
  105. lastFocusedWidget.showNextValue();
  106. }
  107. }
  108. });