瀏覽代碼

Adds pick commit button to branches/tags

main
Eric Amodio 3 年之前
父節點
當前提交
315bda0e66
共有 6 個文件被更改,包括 37 次插入11 次删除
  1. +4
    -1
      src/commands/git/merge.ts
  2. +4
    -1
      src/commands/git/rebase.ts
  3. +5
    -3
      src/commands/gitCommands.ts
  4. +5
    -3
      src/commands/quickCommand.buttons.ts
  5. +11
    -2
      src/commands/quickCommand.steps.ts
  6. +8
    -1
      src/commands/quickCommand.ts

+ 4
- 1
src/commands/git/merge.ts 查看文件

@ -24,6 +24,7 @@ interface Context {
cache: Map<string, Promise<GitLog | undefined>>;
destination: GitBranch;
pickCommit: boolean;
pickCommitForItem: boolean;
selectedBranchOrTag: GitReference | undefined;
showTags: boolean;
title: string;
@ -80,6 +81,7 @@ export class MergeGitCommand extends QuickCommand {
cache: new Map<string, Promise<GitLog | undefined>>(),
destination: undefined!,
pickCommit: false,
pickCommitForItem: false,
selectedBranchOrTag: undefined,
showTags: true,
title: this.title,
@ -120,6 +122,7 @@ export class MergeGitCommand extends QuickCommand {
}
context.title = `${this.title} into ${GitReference.toString(context.destination, { icon: false })}`;
context.pickCommitForItem = false;
if (state.counter < 2 || state.reference == null) {
const pickCommitToggle = new QuickCommandButtons.PickCommitToggle(context.pickCommit, context, () => {
@ -153,7 +156,7 @@ export class MergeGitCommand extends QuickCommand {
if (
state.counter < 3 &&
context.selectedBranchOrTag != null &&
(context.pickCommit || state.reference.ref === context.destination.ref)
(context.pickCommit || context.pickCommitForItem || state.reference.ref === context.destination.ref)
) {
const ref = context.selectedBranchOrTag.ref;

+ 4
- 1
src/commands/git/rebase.ts 查看文件

@ -25,6 +25,7 @@ interface Context {
cache: Map<string, Promise<GitLog | undefined>>;
destination: GitBranch;
pickCommit: boolean;
pickCommitForItem: boolean;
selectedBranchOrTag: GitReference | undefined;
showTags: boolean;
title: string;
@ -101,6 +102,7 @@ export class RebaseGitCommand extends QuickCommand {
cache: new Map<string, Promise<GitLog | undefined>>(),
destination: undefined!,
pickCommit: false,
pickCommitForItem: false,
selectedBranchOrTag: undefined,
showTags: true,
title: this.title,
@ -141,6 +143,7 @@ export class RebaseGitCommand extends QuickCommand {
}
context.title = `${this.title} ${GitReference.toString(context.destination, { icon: false })}`;
context.pickCommitForItem = false;
if (state.counter < 2 || state.reference == null) {
const pickCommitToggle = new QuickCommandButtons.PickCommitToggle(context.pickCommit, context, () => {
@ -174,7 +177,7 @@ export class RebaseGitCommand extends QuickCommand {
if (
state.counter < 3 &&
context.selectedBranchOrTag != null &&
(context.pickCommit || state.reference.ref === context.destination.ref)
(context.pickCommit || context.pickCommitForItem || state.reference.ref === context.destination.ref)
) {
const ref = context.selectedBranchOrTag.ref;

+ 5
- 3
src/commands/gitCommands.ts 查看文件

@ -468,9 +468,11 @@ export class GitCommandsCommand extends Command {
disposables.push(
scope,
quickpick.onDidHide(() => resolve(undefined)),
quickpick.onDidTriggerItemButton(async e =>
step.onDidClickItemButton?.(quickpick, e.button, e.item),
),
quickpick.onDidTriggerItemButton(async e => {
if ((await step.onDidClickItemButton?.(quickpick, e.button, e.item)) === true) {
resolve(await this.nextStep(quickpick, commandsStep.command!, [e.item]));
}
}),
quickpick.onDidTriggerButton(async e => {
if (e === QuickInputButtons.Back) {
void goBack();

+ 5
- 3
src/commands/quickCommand.buttons.ts 查看文件

@ -38,10 +38,7 @@ export class ToggleQuickInputButton implements QuickInputButton {
}
/**
*
* @param quickInput
* @returns `true` if the step should be retried (refreshed)
*
*/
onDidClick?(quickInput: QuickInput): boolean | void | Promise<boolean | void>;
@ -89,6 +86,11 @@ export namespace QuickCommandButtons {
}
};
export const PickCommit: QuickInputButton = {
iconPath: new ThemeIcon('git-commit'),
tooltip: 'Choose a Specific Commit',
};
export const PickCommitToggle = class extends ToggleQuickInputButton {
constructor(on = false, context: { showTags: boolean }, onDidClick?: (quickInput: QuickInput) => void) {
super(

+ 11
- 2
src/commands/quickCommand.steps.ts 查看文件

@ -563,7 +563,7 @@ export async function* pickBranchesStep<
export async function* pickBranchOrTagStep<
State extends PartialStepState & { repo: Repository },
Context extends { repos: Repository[]; showTags?: boolean; title: string },
Context extends { repos: Repository[]; pickCommitForItem?: boolean; showTags?: boolean; title: string },
>(
state: State,
context: Context,
@ -591,7 +591,10 @@ export async function* pickBranchOrTagStep<
const getBranchesAndOrTagsFn = async () => {
return getBranchesAndOrTags(state.repo, context.showTags ? ['branches', 'tags'] : ['branches'], {
buttons: [QuickCommandButtons.RevealInSideBar],
buttons:
typeof context.pickCommitForItem === 'boolean'
? [QuickCommandButtons.PickCommit, QuickCommandButtons.RevealInSideBar]
: [QuickCommandButtons.RevealInSideBar],
filter: filter,
picked: picked,
sort: true,
@ -616,6 +619,11 @@ export async function* pickBranchOrTagStep<
: branchesAndOrTags,
additionalButtons: [...(additionalButtons ?? []), showTagsButton],
onDidClickItemButton: (quickpick, button, { item }) => {
if (button === QuickCommandButtons.PickCommit) {
context.pickCommitForItem = true;
return true;
}
if (button === QuickCommandButtons.RevealInSideBar) {
if (GitReference.isBranch(item)) {
void GitActions.Branch.reveal(item, { select: true, expand: true });
@ -625,6 +633,7 @@ export async function* pickBranchOrTagStep<
void GitActions.Commit.reveal(item, { select: true, expand: true });
}
}
return false;
},
onDidClickButton: async (quickpick, button) => {
if (button === showTagsButton) {

+ 8
- 1
src/commands/quickCommand.ts 查看文件

@ -46,7 +46,14 @@ export interface QuickPickStep {
onDidAccept?(quickpick: QuickPick<T>): boolean | Promise<boolean>;
onDidChangeValue?(quickpick: QuickPick<T>): boolean | Promise<boolean>;
onDidClickButton?(quickpick: QuickPick<T>, button: QuickInputButton): boolean | void | Promise<boolean | void>;
onDidClickItemButton?(quickpick: QuickPick<T>, button: QuickInputButton, item: T): void | Promise<void>;
/**
* @returns `true` if the current item should be selected
*/
onDidClickItemButton?(
quickpick: QuickPick<T>,
button: QuickInputButton,
item: T,
): boolean | void | Promise<boolean | void>;
onDidLoadMore?(quickpick: QuickPick<T>): (DirectiveQuickPickItem | T)[] | Promise<(DirectiveQuickPickItem | T)[]>;
onDidPressKey?(quickpick: QuickPick<T>, key: Keys): void | Promise<void>;
onValidateValue?(quickpick: QuickPick<T>, value: string, items: T[]): boolean | Promise<boolean>;

Loading…
取消
儲存