Skip to content

Commit

Permalink
fix updating items in the quick-pick menu
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Vinokur <ivinokur@redhat.com>
  • Loading branch information
vinokurig committed Sep 6, 2021
1 parent d350116 commit e7865da
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export interface QuickInputService {
Promise<(O extends { canPickMany: true } ? T[] : T) | undefined>;
showQuickPick<T extends QuickPickItem>(items: Array<T>, options?: QuickPickOptions<T>): Promise<T>;
hide(): void;
getCurrentInput(): QuickInput | undefined;
}

/**
Expand Down
25 changes: 21 additions & 4 deletions packages/monaco/src/browser/monaco-quick-input-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import {
InputBox, InputOptions, KeybindingRegistry, PickOptions,
QuickInputButton, QuickInputService, QuickPick, QuickPickItem, QuickPickItemButtonEvent, QuickPickItemHighlights, QuickPickOptions, QuickPickSeparator
InputBox,
InputOptions,
KeybindingRegistry,
PickOptions,
QuickInput,
QuickInputButton,
QuickInputService,
QuickPick,
QuickPickItem,
QuickPickItemButtonEvent,
QuickPickItemHighlights,
QuickPickOptions,
QuickPickSeparator
} from '@theia/core/lib/browser';
import { CancellationToken, Event } from '@theia/core/lib/common';
import { injectable, inject } from '@theia/core/shared/inversify';
Expand Down Expand Up @@ -162,6 +173,7 @@ export class MonacoQuickInputImplementation implements monaco.quickInput.IQuickI
export class MonacoQuickInputService implements QuickInputService {
@inject(MonacoQuickInputImplementation)
private monacoService: MonacoQuickInputImplementation;
private quickInput: QuickInput;

@inject(KeybindingRegistry)
protected readonly keybindingRegistry: KeybindingRegistry;
Expand Down Expand Up @@ -190,9 +202,10 @@ export class MonacoQuickInputService implements QuickInputService {
}

showQuickPick<T extends QuickPickItem>(items: T[], options?: QuickPickOptions<T>): Promise<T> {
const quickPick = this.monacoService.createQuickPick<MonacoQuickPickItem<T>>();
const wrapped = this.wrapQuickPick(quickPick);
this.quickInput = wrapped;
return new Promise<T>((resolve, reject) => {
const quickPick = this.monacoService.createQuickPick<MonacoQuickPickItem<T>>();
const wrapped = this.wrapQuickPick(quickPick);

if (options) {
wrapped.canSelectMany = !!options.canSelectMany;
Expand Down Expand Up @@ -272,6 +285,10 @@ export class MonacoQuickInputService implements QuickInputService {
hide(): void {
return this.monacoService.hide();
}

getCurrentInput(): QuickInput | undefined {
return this.quickInput;
}
}

class MonacoQuickInput {
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-ext/src/main/browser/quick-open-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ export class QuickOpenMainImpl implements QuickOpenMain, Disposable {
matchOnLabel: true,
runIfSingle: false,
});
const input = this.quickInputService.getCurrentInput();
if (input) {
this.sessions.set(sessionId, { input, handlesToItems: new Map() });
}
}

$hide(): void {
Expand Down
13 changes: 10 additions & 3 deletions packages/plugin-ext/src/plugin/quick-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,21 @@ export class QuickPickExt<T extends theia.QuickPickItem> extends QuickInputExt i
return this._items;
}

set items(items: T[]) {
this._items = items.slice();
set items(pickItems: T[]) {
this._items = pickItems.slice();
this._handlesToItems.clear();
this._itemsToHandles.clear();
items.forEach((item, i) => {
pickItems.forEach((item, i) => {
this._handlesToItems.set(i, item);
this._itemsToHandles.set(item, i);
});
const items: T[] = [];
for (let handle = 0; handle < pickItems.length; handle++) {
const item: any = {};
Object.assign(item, pickItems[handle]);
item.value = handle;
items.push(item);
}
this.update({
items
});
Expand Down

0 comments on commit e7865da

Please sign in to comment.