Skip to content

Commit

Permalink
monaco: add support for inQuickOpen (#12427)
Browse files Browse the repository at this point in the history
The commit adds support for the `inQuickOpen` when-clause context which is used to reflect whether there is a quick-open menu currently visible or not.

Signed-off-by: FernandoAscencio <fernando.ascencio.cama@ericsson.com>
Co-authored-by: Marc Dumais <marc.dumais@ericsson.com>
  • Loading branch information
FernandoAscencio and marcdumais-work authored Apr 25, 2023
1 parent 17e5269 commit a0e45ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
19 changes: 18 additions & 1 deletion examples/api-tests/src/monaco-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ describe('Monaco API', async function () {
const { TokenizationRegistry } = require('@theia/monaco-editor-core/esm/vs/editor/common/languages');
const { MonacoContextKeyService } = require('@theia/monaco/lib/browser/monaco-context-key-service');
const { URI } = require('@theia/monaco-editor-core/esm/vs/base/common/uri');

const { animationFrame } = require('@theia/core/lib/browser/browser');

const container = window.theia.container;
const editorManager = container.get(EditorManager);
const workspaceService = container.get(WorkspaceService);
Expand Down Expand Up @@ -185,4 +186,20 @@ describe('Monaco API', async function () {
assert.isTrue(contextKeys.match(`${key} == ${secondValue}`));
});

it('Supports context key: inQuickOpen', async () => {
const inQuickOpenContextKey = 'inQuickOpen';
const quickOpenCommands = ['file-search.openFile', 'workbench.action.showCommands'];
const CommandThatChangesFocus = 'workbench.files.action.focusFilesExplorer';

for (const cmd of quickOpenCommands) {
assert.isFalse(contextKeys.match(inQuickOpenContextKey));
await commands.executeCommand(cmd);
assert.isTrue(contextKeys.match(inQuickOpenContextKey));

await commands.executeCommand(CommandThatChangesFocus);
await animationFrame();
assert.isFalse(contextKeys.match(inQuickOpenContextKey));
}
});

});
7 changes: 7 additions & 0 deletions 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 @@ -80,6 +81,8 @@ export class MonacoQuickInputImplementation implements IQuickInputService {
protected container: HTMLElement;
private quickInputList: List<unknown>;

protected inQuickOpen: IContextKey<boolean>;

get backButton(): IQuickInputButton { return this.controller.backButton; }
get onShow(): monaco.IEvent<void> { return this.controller.onShow; }
get onHide(): monaco.IEvent<void> { return this.controller.onHide; }
Expand All @@ -89,9 +92,13 @@ export class MonacoQuickInputImplementation implements IQuickInputService {
this.initContainer();
this.initController();
this.quickAccess = new QuickAccessController(this, StandaloneServices.get(IInstantiationService));
this.inQuickOpen = this.contextKeyService.createKey<boolean>('inQuickOpen', false);
this.controller.onShow(() => {
this.container.style.top = this.shell.mainPanel.node.getBoundingClientRect().top + 'px';
this.inQuickOpen.set(true);
});
this.controller.onHide(() => this.inQuickOpen.set(false));

this.themeService.initialized.then(() => this.controller.applyStyles(this.getStyles()));
// Hook into the theming service of Monaco to ensure that the updates are ready.
StandaloneServices.get(IStandaloneThemeService).onDidColorThemeChange(() => this.controller.applyStyles(this.getStyles()));
Expand Down

0 comments on commit a0e45ce

Please sign in to comment.