diff --git a/src/commands/diffWithRevision.ts b/src/commands/diffWithRevision.ts index 80c51a99c1c7b..f17d68ec8c5b3 100644 --- a/src/commands/diffWithRevision.ts +++ b/src/commands/diffWithRevision.ts @@ -56,21 +56,23 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand { 'Choose a commit to compare with', { picked: gitUri.sha, - keys: ['right', 'alt+right', 'ctrl+right'], - onDidPressKey: async (key, item) => { - void (await executeCommand(Commands.DiffWith, { - repoPath: gitUri.repoPath, - lhs: { - sha: item.item.ref, - uri: gitUri, - }, - rhs: { - sha: '', - uri: gitUri, - }, - line: args!.line, - showOptions: args!.showOptions, - })); + keyboard: { + keys: ['right', 'alt+right', 'ctrl+right'], + onDidPressKey: async (key, item) => { + await executeCommand(Commands.DiffWith, { + repoPath: gitUri.repoPath, + lhs: { + sha: item.item.ref, + uri: gitUri, + }, + rhs: { + sha: '', + uri: gitUri, + }, + line: args!.line, + showOptions: args!.showOptions, + }); + }, }, showOtherReferences: [ CommandQuickPickItem.fromCommand('Choose a Branch or Tag...', Commands.DiffWithRevisionFrom), diff --git a/src/commands/gitCommands.ts b/src/commands/gitCommands.ts index 75c29cb967dfa..8e6bcb4c3ef1c 100644 --- a/src/commands/gitCommands.ts +++ b/src/commands/gitCommands.ts @@ -363,6 +363,9 @@ export class GitCommandsCommand extends Command { const scope = this.container.keyboard.createScope(mapping); void scope.start(); + if (step.value != null) { + void scope.pause(['left', 'ctrl+left', 'right', 'ctrl+right']); + } disposables.push( scope, @@ -404,9 +407,9 @@ export class GitCommandsCommand extends Command { if (scope != null) { // Pause the left/right keyboard commands if there is a value, otherwise the left/right arrows won't work in the input properly if (e.length !== 0) { - await scope.pause(['left', 'right']); + void scope.pause(['left', 'ctrl+left', 'right', 'ctrl+right']); } else { - await scope.resume(); + void scope.resume(); } } @@ -521,6 +524,9 @@ export class GitCommandsCommand extends Command { const scope = this.container.keyboard.createScope(mapping); void scope.start(); + if (step.value != null) { + void scope.pause(['left', 'ctrl+left', 'right', 'ctrl+right']); + } let overrideItems = false; @@ -592,9 +598,9 @@ export class GitCommandsCommand extends Command { if (scope != null) { // Pause the left/right keyboard commands if there is a value, otherwise the left/right arrows won't work in the input properly if (e.length !== 0) { - await scope.pause(['left', 'right']); + void scope.pause(['left', 'ctrl+left', 'right', 'ctrl+right']); } else { - await scope.resume(); + void scope.resume(); } } diff --git a/src/commands/openFileAtRevision.ts b/src/commands/openFileAtRevision.ts index fc645e61cf8e0..e3b82ab2be960 100644 --- a/src/commands/openFileAtRevision.ts +++ b/src/commands/openFileAtRevision.ts @@ -133,14 +133,16 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand { `Choose a commit to ${args.annotationType === 'blame' ? 'blame' : 'open'} the file revision from`, { picked: gitUri.sha, - keys: ['right', 'alt+right', 'ctrl+right'], - onDidPressKey: async (key, item) => { - await openFileAtRevision(item.item.file!, item.item, { - annotationType: args!.annotationType, - line: args!.line, - preserveFocus: true, - preview: false, - }); + keyboard: { + keys: ['right', 'alt+right', 'ctrl+right'], + onDidPressKey: async (key, item) => { + await openFileAtRevision(item.item.file!, item.item, { + annotationType: args!.annotationType, + line: args!.line, + preserveFocus: true, + preview: true, + }); + }, }, showOtherReferences: [ CommandQuickPickItem.fromCommand( diff --git a/src/commands/openFileAtRevisionFrom.ts b/src/commands/openFileAtRevisionFrom.ts index 563ac4b638e6c..47d3a859d3fb6 100644 --- a/src/commands/openFileAtRevisionFrom.ts +++ b/src/commands/openFileAtRevisionFrom.ts @@ -65,20 +65,19 @@ export class OpenFileAtRevisionFromCommand extends ActiveEditorCommand { 'Choose a branch or tag to open the file revision from', { allowEnteringRefs: true, - keys: ['right', 'alt+right', 'ctrl+right'], - onDidPressKey: async (key, quickpick) => { - const [item] = quickpick.activeItems; - if (item != null) { + keyboard: { + keys: ['right', 'alt+right', 'ctrl+right'], + onDidPressKey: async (key, item) => { await openFileAtRevision( this.container.git.getRevisionUri(item.ref, gitUri.fsPath, gitUri.repoPath!), { annotationType: args!.annotationType, line: args!.line, preserveFocus: true, - preview: false, + preview: true, }, ); - } + }, }, }, ); diff --git a/src/quickpicks/commitPicker.ts b/src/quickpicks/commitPicker.ts index e4beb37eab012..7a2f5333dc4b3 100644 --- a/src/quickpicks/commitPicker.ts +++ b/src/quickpicks/commitPicker.ts @@ -22,8 +22,10 @@ export async function showCommitPicker( placeholder: string, options?: { picked?: string; - keys?: Keys[]; - onDidPressKey?(key: Keys, item: CommitQuickPickItem): void | Promise; + keyboard?: { + keys: Keys[]; + onDidPressKey(key: Keys, item: CommitQuickPickItem): void | Promise; + }; showOtherReferences?: CommandQuickPickItem[]; }, ): Promise { @@ -98,17 +100,23 @@ export async function showCommitPicker( const disposables: Disposable[] = []; let scope: KeyboardScope | undefined; - if (options?.keys != null && options.keys.length !== 0 && options?.onDidPressKey !== null) { + if (options?.keyboard != null) { + const { keyboard } = options; scope = Container.instance.keyboard.createScope( Object.fromEntries( - options.keys.map(key => [ + keyboard.keys.map(key => [ key, { - onDidPressKey: key => { + onDidPressKey: async key => { if (quickpick.activeItems.length !== 0) { const [item] = quickpick.activeItems; if (item != null && !isDirectiveQuickPickItem(item) && !CommandQuickPickItem.is(item)) { - void options.onDidPressKey!(key, item); + const ignoreFocusOut = quickpick.ignoreFocusOut; + quickpick.ignoreFocusOut = true; + + await keyboard.onDidPressKey(key, item); + + quickpick.ignoreFocusOut = ignoreFocusOut; } } }, @@ -143,14 +151,14 @@ export async function showCommitPicker( resolve(item); } }), - quickpick.onDidChangeValue(async e => { + quickpick.onDidChangeValue(value => { if (scope == null) return; // Pause the left/right keyboard commands if there is a value, otherwise the left/right arrows won't work in the input properly - if (e.length !== 0) { - await scope.pause(['left', 'right']); + if (value.length !== 0) { + void scope.pause(['left', 'ctrl+left', 'right', 'ctrl+right']); } else { - await scope.resume(); + void scope.resume(); } }), ); @@ -182,8 +190,10 @@ export async function showStashPicker( options?: { empty?: string; filter?: (c: GitStashCommit) => boolean; - keys?: Keys[]; - onDidPressKey?(key: Keys, item: CommitQuickPickItem): void | Promise; + keyboard?: { + keys: Keys[]; + onDidPressKey(key: Keys, item: CommitQuickPickItem): void | Promise; + }; picked?: string; showOtherReferences?: CommandQuickPickItem[]; }, @@ -231,17 +241,23 @@ export async function showStashPicker( const disposables: Disposable[] = []; let scope: KeyboardScope | undefined; - if (options?.keys != null && options.keys.length !== 0 && options?.onDidPressKey !== null) { + if (options?.keyboard != null) { + const { keyboard } = options; scope = Container.instance.keyboard.createScope( Object.fromEntries( - options.keys.map(key => [ + keyboard.keys.map(key => [ key, { - onDidPressKey: key => { + onDidPressKey: async key => { if (quickpick.activeItems.length !== 0) { const [item] = quickpick.activeItems; if (item != null && !isDirectiveQuickPickItem(item) && !CommandQuickPickItem.is(item)) { - void options.onDidPressKey!(key, item); + const ignoreFocusOut = quickpick.ignoreFocusOut; + quickpick.ignoreFocusOut = true; + + await keyboard.onDidPressKey(key, item); + + quickpick.ignoreFocusOut = ignoreFocusOut; } } }, @@ -270,14 +286,14 @@ export async function showStashPicker( resolve(item); } }), - quickpick.onDidChangeValue(async e => { + quickpick.onDidChangeValue(value => { if (scope == null) return; // Pause the left/right keyboard commands if there is a value, otherwise the left/right arrows won't work in the input properly - if (e.length !== 0) { - await scope.pause(['left', 'right']); + if (value.length !== 0) { + void scope.pause(['left', 'ctrl+left', 'right', 'ctrl+right']); } else { - await scope.resume(); + void scope.resume(); } }), ); diff --git a/src/quickpicks/referencePicker.ts b/src/quickpicks/referencePicker.ts index 31842679989d7..6cc7573ffa90b 100644 --- a/src/quickpicks/referencePicker.ts +++ b/src/quickpicks/referencePicker.ts @@ -1,4 +1,4 @@ -import type { Disposable, QuickPick } from 'vscode'; +import type { Disposable } from 'vscode'; import { CancellationTokenSource, window } from 'vscode'; import { RevealInSideBarQuickInputButton } from '../commands/quickCommand.buttons'; import { getBranchesAndOrTags, getValidateGitReferenceFn } from '../commands/quickCommand.steps'; @@ -35,8 +35,10 @@ export interface ReferencesQuickPickOptions { picked?: string; filter?: { branches?(b: GitBranch): boolean; tags?(t: GitTag): boolean }; include?: ReferencesQuickPickIncludes; - keys?: Keys[]; - onDidPressKey?(key: Keys, quickpick: QuickPick): void | Promise; + keyboard?: { + keys: Keys[]; + onDidPressKey(key: Keys, item: ReferencesQuickPickItem): void | Promise; + }; sort?: boolean | { branches?: BranchSortOptions; tags?: TagSortOptions }; } @@ -44,14 +46,14 @@ export async function showReferencePicker( repoPath: string, title: string, placeHolder: string, - options: ReferencesQuickPickOptions = {}, + options?: ReferencesQuickPickOptions, ): Promise { const quickpick = window.createQuickPick(); quickpick.ignoreFocusOut = getQuickPickIgnoreFocusOut(); quickpick.title = title; quickpick.placeholder = - options.allowEnteringRefs != null + options?.allowEnteringRefs != null ? `${placeHolder}${GlyphChars.Space.repeat(3)}(or enter a reference using #)` : placeHolder; quickpick.matchOnDescription = true; @@ -59,15 +61,24 @@ export async function showReferencePicker( const disposables: Disposable[] = []; let scope: KeyboardScope | undefined; - if (options?.keys != null && options.keys.length !== 0 && options?.onDidPressKey !== null) { + if (options?.keyboard != null) { + const { keyboard } = options; scope = Container.instance.keyboard.createScope( Object.fromEntries( - options.keys.map(key => [ + keyboard.keys.map(key => [ key, { - onDidPressKey: key => { + onDidPressKey: async key => { if (quickpick.activeItems.length !== 0) { - void options.onDidPressKey!(key, quickpick); + const [item] = quickpick.activeItems; + if (item != null) { + const ignoreFocusOut = quickpick.ignoreFocusOut; + quickpick.ignoreFocusOut = true; + + await keyboard.onDidPressKey(key, item); + + quickpick.ignoreFocusOut = ignoreFocusOut; + } } }, }, @@ -82,7 +93,7 @@ export async function showReferencePicker( let autoPick; let items = getItems(repoPath, options); - if (options.autoPick) { + if (options?.autoPick) { items = items.then(itms => { if (itms.length <= 1) { autoPick = itms[0]; @@ -93,7 +104,6 @@ export async function showReferencePicker( } quickpick.busy = true; - quickpick.show(); const getValidateGitReference = getValidateGitReferenceFn(Container.instance.git.getRepository(repoPath), { @@ -105,7 +115,6 @@ export async function showReferencePicker( }); quickpick.items = await items; - quickpick.busy = false; try { @@ -119,19 +128,19 @@ export async function showReferencePicker( resolve(quickpick.activeItems[0]); }), quickpick.onDidChangeValue(async e => { - if (options.allowEnteringRefs) { - if (!(await getValidateGitReference(quickpick, e))) { - quickpick.items = await items; + if (scope != null) { + // Pause the left/right keyboard commands if there is a value, otherwise the left/right arrows won't work in the input properly + if (e.length !== 0) { + void scope.pause(['left', 'ctrl+left', 'right', 'ctrl+right']); + } else { + void scope.resume(); } } - if (scope == null) return; - - // Pause the left/right keyboard commands if there is a value, otherwise the left/right arrows won't work in the input properly - if (e.length !== 0) { - await scope.pause(['left', 'right']); - } else { - await scope.resume(); + if (options?.allowEnteringRefs) { + if (!(await getValidateGitReference(quickpick, e))) { + quickpick.items = await items; + } } }), quickpick.onDidTriggerItemButton(({ button, item: { item } }) => { @@ -162,11 +171,8 @@ export async function showReferencePicker( } } -async function getItems( - repoPath: string, - { picked, filter, include, sort }: ReferencesQuickPickOptions, -): Promise { - include = include ?? ReferencesQuickPickIncludes.BranchesAndTags; +async function getItems(repoPath: string, options?: ReferencesQuickPickOptions): Promise { + const include = options?.include ?? ReferencesQuickPickIncludes.BranchesAndTags; const items: ReferencesQuickPickItem[] = await getBranchesAndOrTags( Container.instance.git.getRepository(repoPath), @@ -179,13 +185,14 @@ async function getItems( : [], { buttons: [RevealInSideBarQuickInputButton], - filter: filter, - picked: picked, - sort: sort ?? { branches: { current: false }, tags: {} }, + filter: options?.filter, + picked: options?.picked, + sort: options?.sort ?? { branches: { current: false }, tags: {} }, }, ); // Move the picked item to the top + const picked = options?.picked; if (picked) { const index = items.findIndex(i => i.ref === picked); if (index !== -1) {