quick access - restore support for using last typed value when opening again
This commit is contained in:
parent
44a832ca03
commit
042fded9b6
|
@ -17,6 +17,7 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
|
|||
private readonly mapProviderToDescriptor = new Map<IQuickAccessProviderDescriptor, IQuickAccessProvider>();
|
||||
|
||||
private lastActivePicker: IQuickPick<IQuickPickItem> | undefined = undefined;
|
||||
private lastPickerInputs = new Map<IQuickAccessProviderDescriptor, string>();
|
||||
|
||||
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));
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -179,7 +179,10 @@ export class QuickOpenController extends Component implements IQuickOpenService
|
|||
|
||||
show(prefix?: string, options?: IShowOptions): Promise<void> {
|
||||
if (this.useNewExperimentalVersion) {
|
||||
this.quickInputService.quickAccess.show(prefix, options);
|
||||
this.quickInputService.quickAccess.show(prefix, {
|
||||
...options,
|
||||
inputUseLastValue: !prefix && this.preserveInput
|
||||
});
|
||||
|
||||
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 { 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 = <IWorkbenchQuickOpenConfiguration>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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue