From b52d45406171de36cfe6d07de9a1937d41f75092 Mon Sep 17 00:00:00 2001 From: Federico Bozzini Date: Fri, 31 Mar 2023 14:06:06 +0100 Subject: [PATCH 1/2] Revert "Fixed QuickInput behavior on Enter" This reverts commit 6a029ece395b5fc73f12601f095617d6adf55a13. --- packages/monaco/src/browser/monaco-quick-input-service.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/monaco/src/browser/monaco-quick-input-service.ts b/packages/monaco/src/browser/monaco-quick-input-service.ts index 7f3d4920a0114..595fa969f3798 100644 --- a/packages/monaco/src/browser/monaco-quick-input-service.ts +++ b/packages/monaco/src/browser/monaco-quick-input-service.ts @@ -277,10 +277,7 @@ export class MonacoQuickInputService implements QuickInputService { options.onDidAccept(); } wrapped.hide(); - const firstSelectedElement = wrapped.selectedItems[0]; - const firstElement = wrapped.items.find(i => !QuickPickSeparator.is(i)) as T | undefined; - const result = firstSelectedElement || firstElement; - resolve(result); + resolve(wrapped.selectedItems[0]); }); wrapped.onDidHide(() => { From beb31bbe8d0a79d16b0d8b3abdb38cb5ceed2cd6 Mon Sep 17 00:00:00 2001 From: FernandoAscencio <48699277+FernandoAscencio@users.noreply.github.com> Date: Thu, 9 Mar 2023 05:19:12 -0500 Subject: [PATCH 2/2] Quick pick fix Signed-off-by: Federico Bozzini --- .../browser/menu/sample-menu-contribution.ts | 11 ++++++++++ .../src/browser/monaco-quick-input-service.ts | 22 ++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/examples/api-samples/src/browser/menu/sample-menu-contribution.ts b/examples/api-samples/src/browser/menu/sample-menu-contribution.ts index 737de89995350..8ed3847009f52 100644 --- a/examples/api-samples/src/browser/menu/sample-menu-contribution.ts +++ b/examples/api-samples/src/browser/menu/sample-menu-contribution.ts @@ -53,6 +53,17 @@ export class SampleCommandContribution implements CommandContribution { protected readonly messageService: MessageService; registerCommands(commands: CommandRegistry): void { + commands.registerCommand({ id: 'create-quick-pick-sample', label: 'Internal QuickPick' }, { + execute: () => { + const pick = this.quickInputService.createQuickPick(); + pick.items = [{ label: '1' }, { label: '2' }, { label: '3' }]; + pick.onDidAccept(() => { + console.log(`accepted: ${pick.selectedItems[0]?.label}`); + pick.hide(); + }); + pick.show(); + } + }); commands.registerCommand(SampleCommand, { execute: () => { alert('This is a sample command!'); diff --git a/packages/monaco/src/browser/monaco-quick-input-service.ts b/packages/monaco/src/browser/monaco-quick-input-service.ts index 595fa969f3798..192096e1ef13f 100644 --- a/packages/monaco/src/browser/monaco-quick-input-service.ts +++ b/packages/monaco/src/browser/monaco-quick-input-service.ts @@ -181,7 +181,7 @@ export class MonacoQuickInputImplementation implements IQuickInputService { idPrefix: 'quickInput_', container: this.container, ignoreFocusOut: () => false, - isScreenReaderOptimized: () => true, + isScreenReaderOptimized: () => false, // TODO change to true once support is added. backKeybindingLabel: () => undefined, setContextKey: (id?: string) => this.setContextKey(id), returnFocus: () => this.container.focus(), @@ -251,8 +251,8 @@ export class MonacoQuickInputService implements QuickInputService { showQuickPick(items: Array, options?: QuickPickOptions): Promise { return new Promise((resolve, reject) => { - const quickPick = this.monacoService.createQuickPick>(); - const wrapped = this.wrapQuickPick(quickPick); + const wrapped = this.createQuickPick(); + wrapped.items = items; if (options) { wrapped.canSelectMany = !!options.canSelectMany; @@ -487,26 +487,28 @@ class MonacoQuickPick extends MonacoQuickInput implemen return this.wrapped.items.map(item => QuickPickSeparator.is(item) ? item : item.item); } - set items(itms: readonly (T | QuickPickSeparator)[]) { + set items(itemList: readonly (T | QuickPickSeparator)[]) { // We need to store and apply the currently selected active items. // Since monaco compares these items by reference equality, creating new wrapped items will unmark any active items. // Assigning the `activeItems` again will restore all active items even after the items array has changed. // See also the `findMonacoItemReferences` method. const active = this.activeItems; - this.wrapped.items = itms.map(item => QuickPickSeparator.is(item) ? item : new MonacoQuickPickItem(item, this.keybindingRegistry)); - this.activeItems = active; + this.wrapped.items = itemList.map(item => QuickPickSeparator.is(item) ? item : new MonacoQuickPickItem(item, this.keybindingRegistry)); + if (active.length !== 0) { + this.activeItems = active; // If this is done with an empty activeItems array, then it will undo first item focus on quick menus. + } } - set activeItems(itms: readonly T[]) { - this.wrapped.activeItems = this.findMonacoItemReferences(this.wrapped.items, itms); + set activeItems(itemList: readonly T[]) { + this.wrapped.activeItems = this.findMonacoItemReferences(this.wrapped.items, itemList); } get activeItems(): readonly (T)[] { return this.wrapped.activeItems.map(item => item.item); } - set selectedItems(itms: readonly T[]) { - this.wrapped.selectedItems = this.findMonacoItemReferences(this.wrapped.items, itms); + set selectedItems(itemList: readonly T[]) { + this.wrapped.selectedItems = this.findMonacoItemReferences(this.wrapped.items, itemList); } get selectedItems(): readonly (T)[] {