Skip to content
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

Add optional sortByLabel to QuickPick to control whether to re-sort results #77297

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/vs/platform/quickinput/common/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export interface IPickOptions<T extends IQuickPickItem> {
*/
matchOnLabel?: boolean;

/**
* an optional flag to sort the final results by index of first query match in label. Defaults to true.
*/
sortByLabel?: boolean;

/**
* an option flag to control whether focus is always automatically brought to a list item. Defaults to true.
*/
Expand Down Expand Up @@ -188,6 +193,8 @@ export interface IQuickPick<T extends IQuickPickItem> extends IQuickInput {

matchOnLabel: boolean;

sortByLabel: boolean;

autoFocusOnList: boolean;

quickNavigate: IQuickNavigateConfiguration | undefined;
Expand Down
10 changes: 10 additions & 0 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,11 @@ declare module 'vscode' {
*/
matchOnDetail?: boolean;

/**
* An optional flag to sort the final results by index of first query match in label, defaults to true.
*/
sortByLabel?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes should be in vscode.proposed.d.ts, new API starts there until we decide to release it as stable API. More info: https:/Microsoft/vscode/wiki/Extension-API-process


/**
* An optional string to show as place holder in the input box to guide the user what to pick on.
*/
Expand Down Expand Up @@ -7327,6 +7332,11 @@ declare module 'vscode' {
*/
matchOnDetail: boolean;

/**
* An optional flag to sort the final results by index of first query match in label. Defaults to true.
*/
sortByLabel: boolean;

/**
* Active items. This can be read and updated by the extension.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ export interface TransferQuickPick extends BaseTransferQuickInput {

matchOnDescription?: boolean;

sortByLabel?: boolean;

matchOnDetail?: boolean;
}

Expand Down
11 changes: 11 additions & 0 deletions src/vs/workbench/api/common/extHostQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class ExtHostQuickOpen implements ExtHostQuickOpenShape {
placeHolder: options && options.placeHolder,
matchOnDescription: options && options.matchOnDescription,
matchOnDetail: options && options.matchOnDetail,
sortByLabel: options && options.sortByLabel,
ignoreFocusLost: options && options.ignoreFocusOut,
canPickMany: options && options.canPickMany
}, token);
Expand Down Expand Up @@ -485,6 +486,7 @@ class ExtHostQuickPick<T extends QuickPickItem> extends ExtHostQuickInput implem
private _canSelectMany = false;
private _matchOnDescription = true;
private _matchOnDetail = true;
private _sortByLabel = true;
private _activeItems: T[] = [];
private _onDidChangeActiveEmitter = new Emitter<T[]>();
private _selectedItems: T[] = [];
Expand Down Expand Up @@ -550,6 +552,15 @@ class ExtHostQuickPick<T extends QuickPickItem> extends ExtHostQuickInput implem
this.update({ matchOnDetail });
}

get sortByLabel() {
return this._sortByLabel;
}

set sortByLabel(sortByLabel: boolean) {
this._sortByLabel = sortByLabel;
this.update({ sortByLabel });
}

get activeItems() {
return this._activeItems;
}
Expand Down
14 changes: 14 additions & 0 deletions src/vs/workbench/browser/parts/quickinput/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
private _matchOnDescription = false;
private _matchOnDetail = false;
private _matchOnLabel = true;
private _sortByLabel = true;
private _autoFocusOnList = true;
private _activeItems: T[] = [];
private activeItemsUpdated = false;
Expand Down Expand Up @@ -426,6 +427,16 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
this.update();
}

get sortByLabel() {
return this._sortByLabel;
}

set sortByLabel(sortByLabel: boolean) {
this._sortByLabel = sortByLabel;
this.update();
}


get autoFocusOnList() {
return this._autoFocusOnList;
}
Expand Down Expand Up @@ -753,6 +764,7 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
this.ui.list.matchOnDescription = this.matchOnDescription;
this.ui.list.matchOnDetail = this.matchOnDetail;
this.ui.list.matchOnLabel = this.matchOnLabel;
this.ui.list.sortByLabel = this.sortByLabel;
this.ui.setComboboxAccessibility(true);
this.ui.inputBox.setAttribute('aria-label', QuickPick.INPUT_BOX_ARIA_LABEL);
this.ui.setVisibilities(this.canSelectMany ? { title: !!this.title || !!this.step, checkAll: true, inputBox: true, visibleCount: true, count: true, ok: true, list: true, message: !!this.validationMessage } : { title: !!this.title || !!this.step, inputBox: true, visibleCount: true, list: true, message: !!this.validationMessage, customButton: this.customButton, ok: this.ok });
Expand Down Expand Up @@ -1249,6 +1261,7 @@ export class QuickInputService extends Component implements IQuickInputService {
input.matchOnDescription = !!options.matchOnDescription;
input.matchOnDetail = !!options.matchOnDetail;
input.matchOnLabel = (options.matchOnLabel === undefined) || options.matchOnLabel; // default to true
input.sortByLabel = (options.sortByLabel === undefined) || options.sortByLabel; // default to true
input.autoFocusOnList = (options.autoFocusOnList === undefined) || options.autoFocusOnList; // default to true
input.quickNavigate = options.quickNavigate;
input.contextKey = options.contextKey;
Expand Down Expand Up @@ -1368,6 +1381,7 @@ export class QuickInputService extends Component implements IQuickInputService {
this.ui.list.matchOnDescription = false;
this.ui.list.matchOnDetail = false;
this.ui.list.matchOnLabel = true;
this.ui.list.sortByLabel = true;
this.ui.ignoreFocusOut = false;
this.setComboboxAccessibility(false);
this.ui.inputBox.removeAttribute('aria-label');
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/browser/parts/quickinput/quickInputList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export class QuickInputList {
matchOnDescription = false;
matchOnDetail = false;
matchOnLabel = true;
sortByLabel = true;
private _onChangedAllVisibleChecked = new Emitter<boolean>();
onChangedAllVisibleChecked: Event<boolean> = this._onChangedAllVisibleChecked.event;
private _onChangedCheckedCount = new Emitter<number>();
Expand Down Expand Up @@ -515,7 +516,7 @@ export class QuickInputList {
const shownElements = this.elements.filter(element => !element.hidden);

// Sort by value
if (query) {
if (this.sortByLabel && query) {
const normalizedSearchValue = query.toLowerCase();
shownElements.sort((a, b) => {
return compareEntries(a, b, normalizedSearchValue);
Expand Down