Skip to content

Commit ae39141

Browse files
author
Benjamin Pasero
committed
quick access - first cut history results in open anything
1 parent bcc488e commit ae39141

6 files changed

Lines changed: 250 additions & 95 deletions

File tree

src/vs/platform/quickinput/browser/pickerQuickAccess.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ export interface IPickerQuickAccessProviderOptions {
5757
canAcceptInBackground?: boolean;
5858
}
5959

60+
export type FastAndSlowPicksType<T> = { picks: Array<T | IQuickPickSeparator>, additionalPicks: Promise<Array<T | IQuickPickSeparator>> };
61+
62+
function isFastAndSlowPicksType<T>(obj: unknown): obj is FastAndSlowPicksType<T> {
63+
const candidate = obj as FastAndSlowPicksType<T>;
64+
65+
return Array.isArray(candidate.picks) && candidate.additionalPicks instanceof Promise;
66+
}
67+
6068
export abstract class PickerQuickAccessProvider<T extends IPickerQuickAccessItem> extends Disposable implements IQuickAccessProvider {
6169

6270
constructor(private prefix: string, protected options?: IPickerQuickAccessProviderOptions) {
@@ -83,9 +91,26 @@ export abstract class PickerQuickAccessProvider<T extends IPickerQuickAccessItem
8391
// Create new cancellation source for this run
8492
picksCts = new CancellationTokenSource(token);
8593

86-
// Collect picks and support both long running and short
94+
// Collect picks and support both long running and short or combined
8795
const res = this.getPicks(picker.value.substr(this.prefix.length).trim(), disposables.add(new DisposableStore()), picksCts.token);
88-
if (Array.isArray(res)) {
96+
if (isFastAndSlowPicksType(res)) {
97+
picker.items = res.picks;
98+
picker.busy = true;
99+
try {
100+
const additionalPicks = await res.additionalPicks;
101+
if (token.isCancellationRequested) {
102+
return;
103+
}
104+
105+
if (additionalPicks.length > 0) {
106+
picker.items = [...res.picks, ...additionalPicks];
107+
}
108+
} finally {
109+
if (!token.isCancellationRequested) {
110+
picker.busy = false;
111+
}
112+
}
113+
} else if (Array.isArray(res)) {
89114
picker.items = res;
90115
} else {
91116
picker.busy = true;
@@ -159,6 +184,7 @@ export abstract class PickerQuickAccessProvider<T extends IPickerQuickAccessItem
159184
* up when the picker closes.
160185
* @param token for long running tasks, implementors need to check on cancellation
161186
* through this token.
187+
* @returns the picks either directly, as promise or combined fast and slow results.
162188
*/
163-
protected abstract getPicks(filter: string, disposables: DisposableStore, token: CancellationToken): Array<T | IQuickPickSeparator> | Promise<Array<T | IQuickPickSeparator>>;
189+
protected abstract getPicks(filter: string, disposables: DisposableStore, token: CancellationToken): Array<T | IQuickPickSeparator> | Promise<Array<T | IQuickPickSeparator>> | { picks: Array<T | IQuickPickSeparator>, additionalPicks: Promise<Array<T | IQuickPickSeparator>> };
164190
}

src/vs/workbench/browser/parts/editor/editorQuickAccess.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import 'vs/css!./media/editorquickaccess';
67
import { localize } from 'vs/nls';
78
import { IQuickPickSeparator, quickPickItemScorerAccessor, IQuickPickItemWithResource } from 'vs/platform/quickinput/common/quickInput';
89
import { PickerQuickAccessProvider, IPickerQuickAccessItem, TriggerAction } from 'vs/platform/quickinput/browser/pickerQuickAccess';
@@ -99,7 +100,7 @@ export abstract class BaseEditorQuickAccessProvider extends PickerQuickAccessPro
99100
buttonsAlwaysVisible: isDirty,
100101
buttons: [
101102
{
102-
iconClass: isDirty ? 'codicon-circle-filled' : 'codicon-close',
103+
iconClass: isDirty ? 'dirty-editor codicon-circle-filled' : 'codicon-close',
103104
tooltip: localize('closeEditor', "Close Editor")
104105
}
105106
],
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
.quick-input-list .quick-input-list-entry.has-actions:hover .quick-input-list-entry-action-bar .action-label.dirty-editor::before {
7+
content: "\ea76"; /* Close icon flips between black dot and "X" for dirty open editors */
8+
}

0 commit comments

Comments
 (0)