diff --git a/src/vs/platform/quickinput/browser/quickAccess.ts b/src/vs/platform/quickinput/browser/quickAccess.ts index 039afb60687..03e12f09a99 100644 --- a/src/vs/platform/quickinput/browser/quickAccess.ts +++ b/src/vs/platform/quickinput/browser/quickAccess.ts @@ -17,6 +17,7 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon private readonly mapProviderToDescriptor = new Map(); private lastActivePicker: IQuickPick | undefined = undefined; + private lastPickerInputs = new Map(); constructor( @IQuickInputService private readonly quickInputService: IQuickInputService, @@ -34,6 +35,19 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon // Find provider for the value to show const [provider, descriptor] = this.getOrInstantiateProvider(value); + // Rewrite the value to the last input of the provider if told so + // Also adjust the `inputSelection` so that the user can type over + if (descriptor && options?.inputUseLastValue) { + const lastInput = this.lastPickerInputs.get(descriptor); + if (lastInput) { + value = lastInput; + options = { + ...options, + inputSelection: { start: descriptor.prefix.length, end: value.length } + }; + } + } + // Create a picker for the provider to use with the initial value // and adjust the filtering to exclude the prefix from filtering const picker = disposables.add(this.quickInputService.createQuickPick()); @@ -74,6 +88,13 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon } })); + // Remember picker input for future use when accepting + if (descriptor) { + disposables.add(picker.onDidAccept(() => { + this.lastPickerInputs.set(descriptor, picker.value); + })); + } + // Ask provider to fill the picker as needed if we have one if (provider) { disposables.add(provider.provide(picker, cts.token)); diff --git a/src/vs/platform/quickinput/common/quickAccess.ts b/src/vs/platform/quickinput/common/quickAccess.ts index bda7c27125d..cb45f050fbb 100644 --- a/src/vs/platform/quickinput/common/quickAccess.ts +++ b/src/vs/platform/quickinput/common/quickAccess.ts @@ -17,6 +17,11 @@ export interface IQuickAccessOptions { */ inputSelection?: { start: number; end: number; }; + /** + * Allows to seed the input with the value that was previously used. + */ + inputUseLastValue?: boolean; + /** * Allows to enable quick navigate support in quick input. */ diff --git a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts index 5db013a2e95..d5ad6e50395 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts @@ -179,7 +179,10 @@ export class QuickOpenController extends Component implements IQuickOpenService show(prefix?: string, options?: IShowOptions): Promise { if (this.useNewExperimentalVersion) { - this.quickInputService.quickAccess.show(prefix, options); + this.quickInputService.quickAccess.show(prefix, { + ...options, + inputUseLastValue: !prefix && this.preserveInput + }); return Promise.resolve(); } diff --git a/src/vs/workbench/contrib/quickopen/browser/commandsHandler.ts b/src/vs/workbench/contrib/quickopen/browser/commandsHandler.ts index 1afc2e5a6ba..82079778083 100644 --- a/src/vs/workbench/contrib/quickopen/browser/commandsHandler.ts +++ b/src/vs/workbench/contrib/quickopen/browser/commandsHandler.ts @@ -12,7 +12,7 @@ import { Mode, IEntryRunContext, IAutoFocus, IModel, IQuickNavigateConfiguration import { QuickOpenEntryGroup, IHighlight, QuickOpenModel, QuickOpenEntry } from 'vs/base/parts/quickopen/browser/quickOpenModel'; import { IMenuService, MenuId, MenuItemAction, SubmenuItemAction } from 'vs/platform/actions/common/actions'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; -import { QuickOpenHandler, IWorkbenchQuickOpenConfiguration } from 'vs/workbench/browser/quickopen'; +import { QuickOpenHandler, IWorkbenchQuickOpenConfiguration, ENABLE_EXPERIMENTAL_VERSION_CONFIG } from 'vs/workbench/browser/quickopen'; import { IEditorAction } from 'vs/editor/common/editorCommon'; import { matchesWords, matchesPrefix, matchesContiguousSubString, or } from 'vs/base/common/filters'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; @@ -35,6 +35,7 @@ import { timeout } from 'vs/base/common/async'; import { isFirefox } from 'vs/base/browser/browser'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { CommandsHistory } from 'vs/platform/quickinput/browser/commandsQuickAccess'; +import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; export const ALL_COMMANDS_PREFIX = '>'; @@ -163,6 +164,7 @@ export class ShowAllCommandsAction extends Action { id: string, label: string, @IQuickOpenService private readonly quickOpenService: IQuickOpenService, + @IQuickInputService private readonly quickInputService: IQuickInputService, @IConfigurationService private readonly configurationService: IConfigurationService ) { super(id, label); @@ -172,13 +174,18 @@ export class ShowAllCommandsAction extends Action { const config = this.configurationService.getValue(); const restoreInput = config.workbench?.commandPalette?.preserveInput === true; - // Show with last command palette input if any and configured - let value = ALL_COMMANDS_PREFIX; - if (restoreInput && lastCommandPaletteInput) { - value = `${value}${lastCommandPaletteInput}`; - } + if (this.configurationService.getValue(ENABLE_EXPERIMENTAL_VERSION_CONFIG) === true) { + this.quickInputService.quickAccess.show(ALL_COMMANDS_PREFIX, { inputUseLastValue: restoreInput }); + } else { - this.quickOpenService.show(value, { inputSelection: lastCommandPaletteInput ? { start: 1 /* after prefix */, end: value.length } : undefined }); + // Show with last command palette input if any and configured + let value = ALL_COMMANDS_PREFIX; + if (restoreInput && lastCommandPaletteInput) { + value = `${value}${lastCommandPaletteInput}`; + } + + this.quickOpenService.show(value, { inputSelection: lastCommandPaletteInput ? { start: 1 /* after prefix */, end: value.length } : undefined }); + } return Promise.resolve(undefined); }