Skip to content

Commit

Permalink
quick access 💄
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Mar 23, 2020
1 parent 5d792c1 commit 0562301
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions src/vs/platform/quickinput/browser/quickAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon

private readonly lastAcceptedPickerValues = new Map<IQuickAccessProviderDescriptor, string>();

private visibleQuickAccess: { picker: IQuickPick<IQuickPickItem>, descriptor: IQuickAccessProviderDescriptor | undefined, value: string } | undefined = undefined;
private visibleQuickAccess: {
picker: IQuickPick<IQuickPickItem>,
descriptor: IQuickAccessProviderDescriptor | undefined,
value: string
} | undefined = undefined;

constructor(
@IQuickInputService private readonly quickInputService: IQuickInputService,
Expand All @@ -40,14 +44,34 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
// Find provider for the value to show
const [provider, descriptor] = this.getOrInstantiateProvider(value);

// Return early if quick access is already showing on that
// same prefix and simply take over the filter value if it
// is more specific and select it for the user to be able
// to type over
const visibleQuickAccess = this.visibleQuickAccess;
const visibleDescriptor = visibleQuickAccess?.descriptor;
if (visibleQuickAccess && descriptor && visibleDescriptor === descriptor) {

// Take over the value only if it is not matching
// the existing provider prefix or we are to preserve
if (value !== descriptor.prefix && !options?.preserveFilterValue) {
visibleQuickAccess.picker.value = value;
}

// Always adjust selection
this.adjustValueSelection(visibleQuickAccess.picker, descriptor, options);

return;
}

// Rewrite the filter value based on certain rules unless disabled
if (descriptor && !options?.preserveFilterValue) {
let newValue: string | undefined = undefined;

// If we have a visible provider with a value, take it's filter value but
// rewrite to new provider prefix in case they differ
if (this.visibleQuickAccess?.descriptor && this.visibleQuickAccess.descriptor !== descriptor) {
const newValueCandidateWithoutPrefix = this.visibleQuickAccess.value.substr(this.visibleQuickAccess.descriptor.prefix.length);
if (visibleQuickAccess && visibleDescriptor && visibleDescriptor !== descriptor) {
const newValueCandidateWithoutPrefix = visibleQuickAccess.value.substr(visibleDescriptor.prefix.length);
if (newValueCandidateWithoutPrefix) {
newValue = `${descriptor.prefix}${newValueCandidateWithoutPrefix}`;
}
Expand All @@ -69,23 +93,6 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
}
}

// Return early if quick access is already showing and
// simply take over the filter value and select it for
// the user to be able to type over
if (descriptor && this.visibleQuickAccess?.descriptor === descriptor) {
const picker = this.visibleQuickAccess.picker;

if (value !== descriptor.prefix && !options?.preserveFilterValue) {
// take over the value only if it is not matching
// the existing provider prefix or we are to preserve
picker.value = value;
}

this.adjustValueSelection(picker, descriptor, options);

return;
}

// Create a picker for the provider to use with the initial value
// and adjust the filtering to exclude the prefix from filtering
const disposables = new DisposableStore();
Expand All @@ -94,7 +101,7 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
this.adjustValueSelection(picker, descriptor, options);
picker.placeholder = descriptor?.placeholder;
picker.quickNavigate = options?.quickNavigateConfiguration;
picker.hideInput = !!picker.quickNavigate && !this.visibleQuickAccess; // only hide input if there was no picker opened already
picker.hideInput = !!picker.quickNavigate && !visibleQuickAccess; // only hide input if there was no picker opened already
picker.autoFocusSecondEntry = !!options?.quickNavigateConfiguration || !!options?.autoFocus?.autoFocusSecondEntry;
picker.contextKey = descriptor?.contextKey;
picker.filterValue = (value: string) => value.substring(descriptor ? descriptor.prefix.length : 0);
Expand Down

0 comments on commit 0562301

Please sign in to comment.