diff --git a/src/vs/platform/quickinput/common/quickInput.ts b/src/vs/platform/quickinput/common/quickInput.ts index c7ec82def00e1..d4fc2b3470bd5 100644 --- a/src/vs/platform/quickinput/common/quickInput.ts +++ b/src/vs/platform/quickinput/common/quickInput.ts @@ -57,6 +57,11 @@ export interface IPickOptions { */ 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. */ @@ -188,6 +193,8 @@ export interface IQuickPick extends IQuickInput { matchOnLabel: boolean; + sortByLabel: boolean; + autoFocusOnList: boolean; quickNavigate: IQuickNavigateConfiguration | undefined; diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 76122f4e69adb..85c635f3ebf09 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1299,4 +1299,21 @@ declare module 'vscode' { } //#endregion + + //#region pelmers - allow QuickPicks to skip sorting + + export interface QuickPick extends QuickInput { + /** + * An optional flag to sort the final results by index of first query match in label. Defaults to true. + */ + sortByLabel: boolean; + } + export interface QuickPickOptions { + /** + * An optional flag to sort the final results by index of first query match in label, defaults to true. + */ + sortByLabel?: boolean; + } + + //#endregion } diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 095d0cd4defbb..89dcc8178781a 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -459,6 +459,8 @@ export interface TransferQuickPick extends BaseTransferQuickInput { matchOnDescription?: boolean; + sortByLabel?: boolean; + matchOnDetail?: boolean; } diff --git a/src/vs/workbench/api/common/extHostQuickOpen.ts b/src/vs/workbench/api/common/extHostQuickOpen.ts index 467b05f5c968b..9b028266b5625 100644 --- a/src/vs/workbench/api/common/extHostQuickOpen.ts +++ b/src/vs/workbench/api/common/extHostQuickOpen.ts @@ -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); @@ -485,6 +486,7 @@ class ExtHostQuickPick extends ExtHostQuickInput implem private _canSelectMany = false; private _matchOnDescription = true; private _matchOnDetail = true; + private _sortByLabel = true; private _activeItems: T[] = []; private _onDidChangeActiveEmitter = new Emitter(); private _selectedItems: T[] = []; @@ -550,6 +552,15 @@ class ExtHostQuickPick 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; } diff --git a/src/vs/workbench/browser/parts/quickinput/quickInput.ts b/src/vs/workbench/browser/parts/quickinput/quickInput.ts index 08e3ff9a240f2..aefdb5c7dc85a 100644 --- a/src/vs/workbench/browser/parts/quickinput/quickInput.ts +++ b/src/vs/workbench/browser/parts/quickinput/quickInput.ts @@ -335,6 +335,7 @@ class QuickPick 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; @@ -426,6 +427,16 @@ class QuickPick 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; } @@ -753,6 +764,7 @@ class QuickPick 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 }); @@ -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; @@ -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'); diff --git a/src/vs/workbench/browser/parts/quickinput/quickInputList.ts b/src/vs/workbench/browser/parts/quickinput/quickInputList.ts index a1b09a2ea46a0..2e904090abbd1 100644 --- a/src/vs/workbench/browser/parts/quickinput/quickInputList.ts +++ b/src/vs/workbench/browser/parts/quickinput/quickInputList.ts @@ -222,6 +222,7 @@ export class QuickInputList { matchOnDescription = false; matchOnDetail = false; matchOnLabel = true; + sortByLabel = true; private _onChangedAllVisibleChecked = new Emitter(); onChangedAllVisibleChecked: Event = this._onChangedAllVisibleChecked.event; private _onChangedCheckedCount = new Emitter(); @@ -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);