contextScopedHistoryWidget.js 5.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 { Context as SuggestContext } from '../../editor/contrib/suggest/suggest.js';
  19. export const HistoryNavigationWidgetContext = 'historyNavigationWidget';
  20. const HistoryNavigationForwardsEnablementContext = 'historyNavigationForwardsEnabled';
  21. const HistoryNavigationBackwardsEnablementContext = 'historyNavigationBackwardsEnabled';
  22. function bindContextScopedWidget(contextKeyService, widget, contextKey) {
  23. new RawContextKey(contextKey, widget).bindTo(contextKeyService);
  24. }
  25. function createWidgetScopedContextKeyService(contextKeyService, widget) {
  26. return contextKeyService.createScoped(widget.target);
  27. }
  28. function getContextScopedWidget(contextKeyService, contextKey) {
  29. return contextKeyService.getContext(document.activeElement).getValue(contextKey);
  30. }
  31. export function createAndBindHistoryNavigationWidgetScopedContextKeyService(contextKeyService, widget) {
  32. const scopedContextKeyService = createWidgetScopedContextKeyService(contextKeyService, widget);
  33. bindContextScopedWidget(scopedContextKeyService, widget, HistoryNavigationWidgetContext);
  34. const historyNavigationForwardsEnablement = new RawContextKey(HistoryNavigationForwardsEnablementContext, true).bindTo(scopedContextKeyService);
  35. const historyNavigationBackwardsEnablement = new RawContextKey(HistoryNavigationBackwardsEnablementContext, true).bindTo(scopedContextKeyService);
  36. return {
  37. scopedContextKeyService,
  38. historyNavigationForwardsEnablement,
  39. historyNavigationBackwardsEnablement,
  40. };
  41. }
  42. let ContextScopedFindInput = class ContextScopedFindInput extends FindInput {
  43. constructor(container, contextViewProvider, options, contextKeyService, showFindOptions = false) {
  44. super(container, contextViewProvider, showFindOptions, options);
  45. this._register(createAndBindHistoryNavigationWidgetScopedContextKeyService(contextKeyService, { target: this.inputBox.element, historyNavigator: this.inputBox }).scopedContextKeyService);
  46. }
  47. };
  48. ContextScopedFindInput = __decorate([
  49. __param(3, IContextKeyService)
  50. ], ContextScopedFindInput);
  51. export { ContextScopedFindInput };
  52. let ContextScopedReplaceInput = class ContextScopedReplaceInput extends ReplaceInput {
  53. constructor(container, contextViewProvider, options, contextKeyService, showReplaceOptions = false) {
  54. super(container, contextViewProvider, showReplaceOptions, options);
  55. this._register(createAndBindHistoryNavigationWidgetScopedContextKeyService(contextKeyService, { target: this.inputBox.element, historyNavigator: this.inputBox }).scopedContextKeyService);
  56. }
  57. };
  58. ContextScopedReplaceInput = __decorate([
  59. __param(3, IContextKeyService)
  60. ], ContextScopedReplaceInput);
  61. export { ContextScopedReplaceInput };
  62. KeybindingsRegistry.registerCommandAndKeybindingRule({
  63. id: 'history.showPrevious',
  64. weight: 200 /* WorkbenchContrib */,
  65. when: ContextKeyExpr.and(ContextKeyExpr.has(HistoryNavigationWidgetContext), ContextKeyExpr.equals(HistoryNavigationBackwardsEnablementContext, true), SuggestContext.Visible.isEqualTo(false)),
  66. primary: 16 /* UpArrow */,
  67. secondary: [512 /* Alt */ | 16 /* UpArrow */],
  68. handler: (accessor) => {
  69. const widget = getContextScopedWidget(accessor.get(IContextKeyService), HistoryNavigationWidgetContext);
  70. if (widget) {
  71. const historyInputBox = widget.historyNavigator;
  72. historyInputBox.showPreviousValue();
  73. }
  74. }
  75. });
  76. KeybindingsRegistry.registerCommandAndKeybindingRule({
  77. id: 'history.showNext',
  78. weight: 200 /* WorkbenchContrib */,
  79. when: ContextKeyExpr.and(ContextKeyExpr.has(HistoryNavigationWidgetContext), ContextKeyExpr.equals(HistoryNavigationForwardsEnablementContext, true), SuggestContext.Visible.isEqualTo(false)),
  80. primary: 18 /* DownArrow */,
  81. secondary: [512 /* Alt */ | 18 /* DownArrow */],
  82. handler: (accessor) => {
  83. const widget = getContextScopedWidget(accessor.get(IContextKeyService), HistoryNavigationWidgetContext);
  84. if (widget) {
  85. const historyInputBox = widget.historyNavigator;
  86. historyInputBox.showNextValue();
  87. }
  88. }
  89. });