quick access - restore support for using last typed value when opening again
This commit is contained in:
parent
44a832ca03
commit
042fded9b6
4 changed files with 44 additions and 8 deletions
|
@ -17,6 +17,7 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
|
||||||
private readonly mapProviderToDescriptor = new Map<IQuickAccessProviderDescriptor, IQuickAccessProvider>();
|
private readonly mapProviderToDescriptor = new Map<IQuickAccessProviderDescriptor, IQuickAccessProvider>();
|
||||||
|
|
||||||
private lastActivePicker: IQuickPick<IQuickPickItem> | undefined = undefined;
|
private lastActivePicker: IQuickPick<IQuickPickItem> | undefined = undefined;
|
||||||
|
private lastPickerInputs = new Map<IQuickAccessProviderDescriptor, string>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@IQuickInputService private readonly quickInputService: IQuickInputService,
|
@IQuickInputService private readonly quickInputService: IQuickInputService,
|
||||||
|
@ -34,6 +35,19 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
|
||||||
// Find provider for the value to show
|
// Find provider for the value to show
|
||||||
const [provider, descriptor] = this.getOrInstantiateProvider(value);
|
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
|
// Create a picker for the provider to use with the initial value
|
||||||
// and adjust the filtering to exclude the prefix from filtering
|
// and adjust the filtering to exclude the prefix from filtering
|
||||||
const picker = disposables.add(this.quickInputService.createQuickPick());
|
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
|
// Ask provider to fill the picker as needed if we have one
|
||||||
if (provider) {
|
if (provider) {
|
||||||
disposables.add(provider.provide(picker, cts.token));
|
disposables.add(provider.provide(picker, cts.token));
|
||||||
|
|
|
@ -17,6 +17,11 @@ export interface IQuickAccessOptions {
|
||||||
*/
|
*/
|
||||||
inputSelection?: { start: number; end: number; };
|
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.
|
* Allows to enable quick navigate support in quick input.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -179,7 +179,10 @@ export class QuickOpenController extends Component implements IQuickOpenService
|
||||||
|
|
||||||
show(prefix?: string, options?: IShowOptions): Promise<void> {
|
show(prefix?: string, options?: IShowOptions): Promise<void> {
|
||||||
if (this.useNewExperimentalVersion) {
|
if (this.useNewExperimentalVersion) {
|
||||||
this.quickInputService.quickAccess.show(prefix, options);
|
this.quickInputService.quickAccess.show(prefix, {
|
||||||
|
...options,
|
||||||
|
inputUseLastValue: !prefix && this.preserveInput
|
||||||
|
});
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { Mode, IEntryRunContext, IAutoFocus, IModel, IQuickNavigateConfiguration
|
||||||
import { QuickOpenEntryGroup, IHighlight, QuickOpenModel, QuickOpenEntry } from 'vs/base/parts/quickopen/browser/quickOpenModel';
|
import { QuickOpenEntryGroup, IHighlight, QuickOpenModel, QuickOpenEntry } from 'vs/base/parts/quickopen/browser/quickOpenModel';
|
||||||
import { IMenuService, MenuId, MenuItemAction, SubmenuItemAction } from 'vs/platform/actions/common/actions';
|
import { IMenuService, MenuId, MenuItemAction, SubmenuItemAction } from 'vs/platform/actions/common/actions';
|
||||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
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 { IEditorAction } from 'vs/editor/common/editorCommon';
|
||||||
import { matchesWords, matchesPrefix, matchesContiguousSubString, or } from 'vs/base/common/filters';
|
import { matchesWords, matchesPrefix, matchesContiguousSubString, or } from 'vs/base/common/filters';
|
||||||
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
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 { isFirefox } from 'vs/base/browser/browser';
|
||||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||||
import { CommandsHistory } from 'vs/platform/quickinput/browser/commandsQuickAccess';
|
import { CommandsHistory } from 'vs/platform/quickinput/browser/commandsQuickAccess';
|
||||||
|
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
|
||||||
|
|
||||||
export const ALL_COMMANDS_PREFIX = '>';
|
export const ALL_COMMANDS_PREFIX = '>';
|
||||||
|
|
||||||
|
@ -163,6 +164,7 @@ export class ShowAllCommandsAction extends Action {
|
||||||
id: string,
|
id: string,
|
||||||
label: string,
|
label: string,
|
||||||
@IQuickOpenService private readonly quickOpenService: IQuickOpenService,
|
@IQuickOpenService private readonly quickOpenService: IQuickOpenService,
|
||||||
|
@IQuickInputService private readonly quickInputService: IQuickInputService,
|
||||||
@IConfigurationService private readonly configurationService: IConfigurationService
|
@IConfigurationService private readonly configurationService: IConfigurationService
|
||||||
) {
|
) {
|
||||||
super(id, label);
|
super(id, label);
|
||||||
|
@ -172,13 +174,18 @@ export class ShowAllCommandsAction extends Action {
|
||||||
const config = <IWorkbenchQuickOpenConfiguration>this.configurationService.getValue();
|
const config = <IWorkbenchQuickOpenConfiguration>this.configurationService.getValue();
|
||||||
const restoreInput = config.workbench?.commandPalette?.preserveInput === true;
|
const restoreInput = config.workbench?.commandPalette?.preserveInput === true;
|
||||||
|
|
||||||
// Show with last command palette input if any and configured
|
if (this.configurationService.getValue(ENABLE_EXPERIMENTAL_VERSION_CONFIG) === true) {
|
||||||
let value = ALL_COMMANDS_PREFIX;
|
this.quickInputService.quickAccess.show(ALL_COMMANDS_PREFIX, { inputUseLastValue: restoreInput });
|
||||||
if (restoreInput && lastCommandPaletteInput) {
|
} else {
|
||||||
value = `${value}${lastCommandPaletteInput}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
return Promise.resolve(undefined);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue