Skip to content

Commit

Permalink
monaco-quick-input-service: set context key "inQuickOpen"
Browse files Browse the repository at this point in the history
Context Key "inQuickOpen" exists in vscode and its value (true or false) reflects
whether the Quick Open, AKA Quick input, is currently open/visible or not.

This context key can be useful in Theia too, e.g. it can be used in the "when"
clause of commands registered by vscode extensions, or programmatically whenever
it's useful to know the state of the Quick Open UI.

Signed-off-by: Marc Dumais <[email protected]>
  • Loading branch information
marcdumais-work committed Apr 4, 2023
1 parent 25af1d9 commit 3d7e8a3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/monaco/src/browser/monaco-quick-input-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { MonacoResolvedKeybinding } from './monaco-resolved-keybinding';
import { IQuickAccessController } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/common/quickAccess';
import { QuickAccessController } from '@theia/monaco-editor-core/esm/vs/platform/quickinput/browser/quickAccess';
import { ContextKeyService as VSCodeContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/browser/contextKeyService';
import { IContextKey } from '@theia/monaco-editor-core/esm/vs/platform/contextkey/common/contextkey';
import { IListOptions, List } from '@theia/monaco-editor-core/esm/vs/base/browser/ui/list/listWidget';
import * as monaco from '@theia/monaco-editor-core';
import { ResolvedKeybinding } from '@theia/monaco-editor-core/esm/vs/base/common/keybindings';
Expand Down Expand Up @@ -76,6 +77,7 @@ export class MonacoQuickInputImplementation implements IQuickInputService {

@inject(VSCodeContextKeyService)
protected readonly contextKeyService: VSCodeContextKeyService;
protected contextKey: IContextKey;

protected container: HTMLElement;
private quickInputList: List<unknown>;
Expand All @@ -100,7 +102,7 @@ export class MonacoQuickInputImplementation implements IQuickInputService {

setContextKey(key: string | undefined): void {
if (key) {
this.contextKeyService.createKey<string>(key, undefined);
this.contextKey = this.contextKeyService.createKey<string>(key, undefined);
}
}

Expand Down Expand Up @@ -177,6 +179,9 @@ export class MonacoQuickInputImplementation implements IQuickInputService {

private initController(): void {
this.controller = new QuickInputController(this.getOptions());
this.setContextKey('inQuickOpen');
this.onShow(() => { this.contextKey.set(true); });
this.onHide(() => { this.contextKey.set(false); });
this.updateLayout();
}

Expand Down

0 comments on commit 3d7e8a3

Please sign in to comment.