Skip to content

Commit eaf60f8

Browse files
author
Benjamin Pasero
committed
quick access - support to auto activate LAST
1 parent 4f0b2b0 commit eaf60f8

7 files changed

Lines changed: 63 additions & 31 deletions

File tree

src/vs/base/parts/quickinput/browser/quickInput.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import 'vs/css!./media/quickInput';
7-
import { IQuickPickItem, IPickOptions, IInputOptions, IQuickNavigateConfiguration, IQuickPick, IQuickInput, IQuickInputButton, IInputBox, IQuickPickItemButtonEvent, QuickPickInput, IQuickPickSeparator, IKeyMods, IQuickPickAcceptEvent, NO_KEY_MODS } from 'vs/base/parts/quickinput/common/quickInput';
7+
import { IQuickPickItem, IPickOptions, IInputOptions, IQuickNavigateConfiguration, IQuickPick, IQuickInput, IQuickInputButton, IInputBox, IQuickPickItemButtonEvent, QuickPickInput, IQuickPickSeparator, IKeyMods, IQuickPickAcceptEvent, NO_KEY_MODS, ItemActivation } from 'vs/base/parts/quickinput/common/quickInput';
88
import * as dom from 'vs/base/browser/dom';
99
import { CancellationToken } from 'vs/base/common/cancellation';
1010
import { QuickInputList, QuickInputListFocus } from './quickInputList';
@@ -391,7 +391,7 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
391391
private _matchOnLabel = true;
392392
private _sortByLabel = true;
393393
private _autoFocusOnList = true;
394-
private _autoFocusSecondEntry = false;
394+
private _itemActivation = ItemActivation.FIRST;
395395
private _activeItems: T[] = [];
396396
private activeItemsUpdated = false;
397397
private activeItemsToConfirm: T[] | null = [];
@@ -527,12 +527,12 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
527527
this.update();
528528
}
529529

530-
get autoFocusSecondEntry() {
531-
return this._autoFocusSecondEntry;
530+
get itemActivation() {
531+
return this._itemActivation;
532532
}
533533

534-
set autoFocusSecondEntry(autoFocusSecondEntry: boolean) {
535-
this._autoFocusSecondEntry = autoFocusSecondEntry;
534+
set itemActivation(itemActivation: ItemActivation) {
535+
this._itemActivation = itemActivation;
536536
}
537537

538538
get activeItems() {
@@ -879,11 +879,18 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
879879
this.ui.checkAll.checked = this.ui.list.getAllVisibleChecked();
880880
this.ui.visibleCount.setCount(this.ui.list.getVisibleCount());
881881
this.ui.count.setCount(this.ui.list.getCheckedCount());
882-
if (this._autoFocusSecondEntry) {
883-
this.ui.list.focus(QuickInputListFocus.Second);
884-
this._autoFocusSecondEntry = false; // only valid once, then unset
885-
} else {
886-
this.trySelectFirst();
882+
switch (this._itemActivation) {
883+
case ItemActivation.SECOND:
884+
this.ui.list.focus(QuickInputListFocus.Second);
885+
this._itemActivation = ItemActivation.FIRST; // only valid once, then unset
886+
break;
887+
case ItemActivation.LAST:
888+
this.ui.list.focus(QuickInputListFocus.Last);
889+
this._itemActivation = ItemActivation.FIRST; // only valid once, then unset
890+
break;
891+
default:
892+
this.trySelectFirst();
893+
break;
887894
}
888895
}
889896
if (this.ui.container.classList.contains('show-checkboxes') !== !!this.canSelectMany) {

src/vs/base/parts/quickinput/common/quickInput.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ export interface IQuickPickAcceptEvent {
182182
inBackground: boolean;
183183
}
184184

185+
export enum ItemActivation {
186+
FIRST = 1,
187+
SECOND,
188+
LAST
189+
}
190+
185191
export interface IQuickPick<T extends IQuickPickItem> extends IQuickInput {
186192

187193
value: string;
@@ -237,20 +243,17 @@ export interface IQuickPick<T extends IQuickPickItem> extends IQuickInput {
237243

238244
autoFocusOnList: boolean;
239245

240-
/**
241-
* If enabled, will try to select the second entry of the picks
242-
* once they appear instead of the first one. This is useful
243-
* e.g. when `quickNavigate` is enabled to be able to select
244-
* a previous entry by just releasing the quick nav keys.
245-
*/
246-
autoFocusSecondEntry: boolean;
247-
248246
quickNavigate: IQuickNavigateConfiguration | undefined;
249247

250248
activeItems: ReadonlyArray<T>;
251249

252250
readonly onDidChangeActive: Event<T[]>;
253251

252+
/**
253+
* Allows to control which entry should be activated by default.
254+
*/
255+
itemActivation: ItemActivation;
256+
254257
selectedItems: ReadonlyArray<T>;
255258

256259
readonly onDidChangeSelection: Event<T[]>;

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

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

6-
import { IQuickInputService, IQuickPick, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
6+
import { IQuickInputService, IQuickPick, IQuickPickItem, ItemActivation } from 'vs/platform/quickinput/common/quickInput';
77
import { Disposable, DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
88
import { IQuickAccessController, IQuickAccessProvider, IQuickAccessRegistry, Extensions, IQuickAccessProviderDescriptor, IQuickAccessOptions, DefaultQuickAccessFilterValue } from 'vs/platform/quickinput/common/quickAccess';
99
import { Registry } from 'vs/platform/registry/common/platform';
@@ -102,7 +102,7 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
102102
picker.placeholder = descriptor?.placeholder;
103103
picker.quickNavigate = options?.quickNavigateConfiguration;
104104
picker.hideInput = !!picker.quickNavigate && !visibleQuickAccess; // only hide input if there was no picker opened already
105-
picker.autoFocusSecondEntry = !!options?.quickNavigateConfiguration || !!options?.autoFocus?.autoFocusSecondEntry;
105+
picker.itemActivation = options?.itemActivation || (options?.quickNavigateConfiguration ? ItemActivation.SECOND : ItemActivation.FIRST);
106106
picker.contextKey = descriptor?.contextKey;
107107
picker.filterValue = (value: string) => value.substring(descriptor ? descriptor.prefix.length : 0);
108108

src/vs/platform/quickinput/common/quickAccess.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
99
import { first, coalesce } from 'vs/base/common/arrays';
1010
import { startsWith } from 'vs/base/common/strings';
1111
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
12+
import { ItemActivation } from 'vs/base/parts/quickinput/common/quickInput';
1213

1314
export interface IQuickAccessOptions {
1415

@@ -18,9 +19,10 @@ export interface IQuickAccessOptions {
1819
quickNavigateConfiguration?: IQuickNavigateConfiguration;
1920

2021
/**
21-
* Wether to select the second pick item by default instead of the first.
22+
* Allows to configure a different item activation strategy.
23+
* By default the first item in the list will get activated.
2224
*/
23-
autoFocus?: { autoFocusSecondEntry?: boolean }
25+
itemActivation?: ItemActivation
2426
}
2527

2628
export interface IQuickAccessController {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ import {
3636
SplitEditorUpAction, SplitEditorDownAction, MoveEditorToLeftGroupAction, MoveEditorToRightGroupAction, MoveEditorToAboveGroupAction, MoveEditorToBelowGroupAction, CloseAllEditorGroupsAction,
3737
JoinAllGroupsAction, FocusLeftGroup, FocusAboveGroup, FocusRightGroup, FocusBelowGroup, EditorLayoutSingleAction, EditorLayoutTwoColumnsAction, EditorLayoutThreeColumnsAction, EditorLayoutTwoByTwoGridAction,
3838
EditorLayoutTwoRowsAction, EditorLayoutThreeRowsAction, EditorLayoutTwoColumnsBottomAction, EditorLayoutTwoRowsRightAction, NewEditorGroupLeftAction, NewEditorGroupRightAction,
39-
NewEditorGroupAboveAction, NewEditorGroupBelowAction, SplitEditorOrthogonalAction, CloseEditorInAllGroupsAction, NavigateToLastEditLocationAction, ToggleGroupSizesAction, ShowAllEditorsByMostRecentlyUsedAction, QuickOpenPreviousRecentlyUsedEditorAction, OpenPreviousRecentlyUsedEditorInGroupAction, OpenNextRecentlyUsedEditorInGroupAction, QuickOpenNextRecentlyUsedEditorAction as QuickOpenLeastRecentlyUsedEditorAction, QuickOpenLeastRecentlyUsedEditorInGroupAction
39+
NewEditorGroupAboveAction, NewEditorGroupBelowAction, SplitEditorOrthogonalAction, CloseEditorInAllGroupsAction, NavigateToLastEditLocationAction, ToggleGroupSizesAction, ShowAllEditorsByMostRecentlyUsedAction,
40+
QuickOpenPreviousRecentlyUsedEditorAction, OpenPreviousRecentlyUsedEditorInGroupAction, OpenNextRecentlyUsedEditorInGroupAction, QuickOpenNextRecentlyUsedEditorAction as QuickOpenLeastRecentlyUsedEditorAction,
41+
QuickOpenLeastRecentlyUsedEditorInGroupAction
4042
} from 'vs/workbench/browser/parts/editor/editorActions';
4143
import * as editorCommands from 'vs/workbench/browser/parts/editor/editorCommands';
4244
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
2424
import { IFileDialogService, ConfirmResult } from 'vs/platform/dialogs/common/dialogs';
2525
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
2626
import { values } from 'vs/base/common/map';
27+
import { ItemActivation } from 'vs/platform/quickinput/common/quickInput';
2728

2829
export class ExecuteCommandAction extends Action {
2930

@@ -1261,6 +1262,7 @@ export class BaseQuickOpenEditorAction extends Action {
12611262
id: string,
12621263
label: string,
12631264
private prefix: string,
1265+
private itemActivation: ItemActivation | undefined,
12641266
@IQuickOpenService private readonly quickOpenService: IQuickOpenService,
12651267
@IKeybindingService private readonly keybindingService: IKeybindingService
12661268
) {
@@ -1270,7 +1272,10 @@ export class BaseQuickOpenEditorAction extends Action {
12701272
async run(): Promise<void> {
12711273
const keybindings = this.keybindingService.lookupKeybindings(this.id);
12721274

1273-
this.quickOpenService.show(this.prefix, { quickNavigateConfiguration: { keybindings } });
1275+
this.quickOpenService.show(this.prefix, {
1276+
quickNavigateConfiguration: { keybindings },
1277+
autoFocus: this.itemActivation === ItemActivation.LAST ? { autoFocusLastEntry: true } : undefined
1278+
});
12741279
}
12751280
}
12761281

@@ -1285,7 +1290,7 @@ export class QuickOpenPreviousRecentlyUsedEditorAction extends BaseQuickOpenEdit
12851290
@IQuickOpenService quickOpenService: IQuickOpenService,
12861291
@IKeybindingService keybindingService: IKeybindingService
12871292
) {
1288-
super(id, label, NAVIGATE_ALL_EDITORS_BY_MOST_RECENTLY_USED_PREFIX, quickOpenService, keybindingService);
1293+
super(id, label, NAVIGATE_ALL_EDITORS_BY_MOST_RECENTLY_USED_PREFIX, undefined, quickOpenService, keybindingService);
12891294
}
12901295
}
12911296

@@ -1300,7 +1305,7 @@ export class QuickOpenNextRecentlyUsedEditorAction extends BaseQuickOpenEditorAc
13001305
@IQuickOpenService quickOpenService: IQuickOpenService,
13011306
@IKeybindingService keybindingService: IKeybindingService
13021307
) {
1303-
super(id, label, NAVIGATE_ALL_EDITORS_BY_MOST_RECENTLY_USED_PREFIX, quickOpenService, keybindingService);
1308+
super(id, label, NAVIGATE_ALL_EDITORS_BY_MOST_RECENTLY_USED_PREFIX, undefined, quickOpenService, keybindingService);
13041309
}
13051310
}
13061311

@@ -1315,7 +1320,7 @@ export class QuickOpenPreviousRecentlyUsedEditorInGroupAction extends BaseQuickO
13151320
@IQuickOpenService quickOpenService: IQuickOpenService,
13161321
@IKeybindingService keybindingService: IKeybindingService
13171322
) {
1318-
super(id, label, NAVIGATE_IN_ACTIVE_GROUP_BY_MOST_RECENTLY_USED_PREFIX, quickOpenService, keybindingService);
1323+
super(id, label, NAVIGATE_IN_ACTIVE_GROUP_BY_MOST_RECENTLY_USED_PREFIX, undefined, quickOpenService, keybindingService);
13191324
}
13201325
}
13211326

@@ -1330,7 +1335,7 @@ export class QuickOpenLeastRecentlyUsedEditorInGroupAction extends BaseQuickOpen
13301335
@IQuickOpenService quickOpenService: IQuickOpenService,
13311336
@IKeybindingService keybindingService: IKeybindingService
13321337
) {
1333-
super(id, label, NAVIGATE_IN_ACTIVE_GROUP_BY_MOST_RECENTLY_USED_PREFIX, quickOpenService, keybindingService);
1338+
super(id, label, NAVIGATE_IN_ACTIVE_GROUP_BY_MOST_RECENTLY_USED_PREFIX, ItemActivation.LAST, quickOpenService, keybindingService);
13341339
}
13351340
}
13361341

src/vs/workbench/browser/parts/quickopen/quickOpenController.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { IEditorService, ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/
4747
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
4848
import { ILabelService } from 'vs/platform/label/common/label';
4949
import { timeout } from 'vs/base/common/async';
50-
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
50+
import { IQuickInputService, IQuickPickItem, ItemActivation } from 'vs/platform/quickinput/common/quickInput';
5151
import { CancellationTokenSource, CancellationToken } from 'vs/base/common/cancellation';
5252
import { IStorageService } from 'vs/platform/storage/common/storage';
5353
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
@@ -179,7 +179,20 @@ export class QuickOpenController extends Component implements IQuickOpenService
179179

180180
show(prefix?: string, options?: IShowOptions): Promise<void> {
181181
if (this.useNewExperimentalVersion) {
182-
this.quickInputService.quickAccess.show(prefix, options);
182+
this.quickInputService.quickAccess.show(prefix, {
183+
quickNavigateConfiguration: options?.quickNavigateConfiguration,
184+
itemActivation: (() => {
185+
if (options?.autoFocus?.autoFocusSecondEntry) {
186+
return ItemActivation.SECOND;
187+
}
188+
189+
if (options?.autoFocus?.autoFocusLastEntry) {
190+
return ItemActivation.LAST;
191+
}
192+
193+
return undefined;
194+
})()
195+
});
183196

184197
return Promise.resolve();
185198
}

0 commit comments

Comments
 (0)