Skip to content

Commit

Permalink
QuickInput: First Element Fallback on Enter
Browse files Browse the repository at this point in the history
This is the first solution step. Might be scrapped.

Signed-off-by: FernandoAScencio <fernando.ascencio.cama@ericsson.com>
  • Loading branch information
FernandoAscencio committed Feb 22, 2023
1 parent 6f53691 commit 0c505a4
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/monaco/src/browser/monaco-quick-input-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class MonacoQuickInputImplementation implements IQuickInputService {
container: this.container,
styles: { widget: {}, list: {}, inputBox: {}, countBadge: {}, button: {}, progressBar: {}, keybindingLabel: {}, },
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(),
Expand Down Expand Up @@ -322,8 +322,7 @@ export class MonacoQuickInputService implements QuickInputService {

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

if (options) {
Expand Down Expand Up @@ -557,26 +556,28 @@ class MonacoQuickPick<T extends QuickPickItem> 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<T>(item, this.keybindingRegistry));
this.activeItems = active;
this.wrapped.items = itemList.map(item => QuickPickSeparator.is(item) ? item : new MonacoQuickPickItem<T>(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)[] {
Expand Down

0 comments on commit 0c505a4

Please sign in to comment.