diff --git a/src/vs/platform/widget/browser/contextScopedHistoryWidget.ts b/src/vs/platform/widget/browser/contextScopedHistoryWidget.ts index bb4c4dc1c869c197864628b66a50739e5c74d791..01335096773a9f600eaaed9ec8c5415ab51cd24b 100644 --- a/src/vs/platform/widget/browser/contextScopedHistoryWidget.ts +++ b/src/vs/platform/widget/browser/contextScopedHistoryWidget.ts @@ -8,7 +8,7 @@ import { IContextKeyService, ContextKeyDefinedExpr, ContextKeyExpr, ContextKeyAn import { HistoryInputBox, IHistoryInputOptions } from 'vs/base/browser/ui/inputbox/inputBox'; import { FindInput, IFindInputOptions } from 'vs/base/browser/ui/findinput/findInput'; import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview'; -import { IContextScopedWidget, getContextScopedWidget, createWidgetScopedContextKeyService } from 'vs/platform/widget/common/contextScopedWidget'; +import { IContextScopedWidget, getContextScopedWidget, createWidgetScopedContextKeyService, bindContextScopedWidget } from 'vs/platform/widget/common/contextScopedWidget'; import { IHistoryNavigationWidget } from 'vs/base/browser/history'; import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; @@ -22,10 +22,10 @@ export interface IContextScopedHistoryNavigationWidget extends IContextScopedWid } -export function createHistoryNavigationWidgetScopedContextKeyService(contextKeyService: IContextKeyService, widget: IContextScopedHistoryNavigationWidget): IContextKeyService { - const scopedContextKeyService = createWidgetScopedContextKeyService(contextKeyService, widget, HistoryNavigationWidgetContext); - const enablementContext = new RawContextKey(HistoryNavigationEnablementContext, true); - enablementContext.bindTo(scopedContextKeyService); +export function createAndBindHistoryNavigationWidgetScopedContextKeyService(contextKeyService: IContextKeyService, widget: IContextScopedHistoryNavigationWidget): IContextKeyService { + const scopedContextKeyService = createWidgetScopedContextKeyService(contextKeyService, widget); + bindContextScopedWidget(scopedContextKeyService, widget, HistoryNavigationWidgetContext); + new RawContextKey(HistoryNavigationEnablementContext, true).bindTo(scopedContextKeyService); return scopedContextKeyService; } @@ -35,7 +35,7 @@ export class ContextScopedHistoryInputBox extends HistoryInputBox { @IContextKeyService contextKeyService: IContextKeyService ) { super(container, contextViewProvider, options); - this._register(createHistoryNavigationWidgetScopedContextKeyService(contextKeyService, { target: this.element, historyNavigator: this })); + this._register(createAndBindHistoryNavigationWidgetScopedContextKeyService(contextKeyService, { target: this.element, historyNavigator: this })); } } @@ -46,7 +46,7 @@ export class ContextScopedFindInput extends FindInput { @IContextKeyService contextKeyService: IContextKeyService ) { super(container, contextViewProvider, options); - this._register(createHistoryNavigationWidgetScopedContextKeyService(contextKeyService, { target: this.inputBox.element, historyNavigator: this.inputBox })); + this._register(createAndBindHistoryNavigationWidgetScopedContextKeyService(contextKeyService, { target: this.inputBox.element, historyNavigator: this.inputBox })); } } diff --git a/src/vs/platform/widget/common/contextScopedWidget.ts b/src/vs/platform/widget/common/contextScopedWidget.ts index c53e10fb11ca807031723b6321e027822cd8713f..4a552485026df1038677d660a977b576b690876e 100644 --- a/src/vs/platform/widget/common/contextScopedWidget.ts +++ b/src/vs/platform/widget/common/contextScopedWidget.ts @@ -6,11 +6,12 @@ import { IContextKeyService, RawContextKey, IContextKeyServiceTarget } from 'vs/platform/contextkey/common/contextkey'; -export function createWidgetScopedContextKeyService(contextKeyService: IContextKeyService, widget: IContextScopedWidget, contextKey: string): IContextKeyService { - const result = contextKeyService.createScoped(widget.target); - const widgetContext = new RawContextKey(contextKey, widget); - widgetContext.bindTo(result); - return result; +export function bindContextScopedWidget(contextKeyService: IContextKeyService, widget: IContextScopedWidget, contextKey: string): void { + new RawContextKey(contextKey, widget).bindTo(contextKeyService); +} + +export function createWidgetScopedContextKeyService(contextKeyService: IContextKeyService, widget: IContextScopedWidget): IContextKeyService { + return contextKeyService.createScoped(widget.target); } export function getContextScopedWidget(contextKeyService: IContextKeyService, contextKey: string): T {