-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
monaco-quick-input-service: set context key "inQuickOpen" #12377
Conversation
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 <marc.dumais@ericsson.com>
b3c87ba
to
de62015
Compare
Signed-off-by: Marc Dumais <marc.dumais@ericsson.com>
de62015
to
38c2e92
Compare
setContextKey(key: string | undefined): void { | ||
if (key) { | ||
this.contextKeyService.createKey<string>(key, undefined); | ||
this.contextKey = this.contextKeyService.createKey<string>(key, undefined); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this method is meant for callers, and it may be problematic for us to set the contextKey
variable especially since we later rely on it for the inQuickOpen
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference VS Code does not keep a single key stored in this case, but a map of them:
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(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the previous comment, I think we can simplify and use the following which is present in other areas of the framework, where we register listeners in the postConstruct
:
+ protected inQuickOpen: ContextKey<boolean>;
@postConstruct()
protected init(): void {
this.initContainer();
this.initController();
+ this.inQuickOpen = this.contextKeyService.createKey<boolean>('inQuickOpen', false);
+ this.onShow(() => { this.inQuickOpen.set(true); });
+ this.onHide(() => { this.inQuickOpen.set(false); })
Closing in favor of #12427 - thanks @FernandoAscencio ! |
What it does
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 set programmatically whenever it's useful to know the state of the Quick Open UI.
How to test
I have provided a test in the browser suite. Confirm that CI passes.
Review checklist
Reminder for reviewers