Skip to content

Commit 18305b9

Browse files
committed
When editing title, skip strategy selection and go straight to input
In the settings phase, you've already selected a title strategy. Changing the strategy at that point is unlikely. The old behaviour can still be triggered by using ctrl+t Fixes #212
1 parent e372a2d commit 18305b9

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

commands/pick/pick-command.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { checkDependencies } from './steps/check-dependencies.ts';
1515
import { ColorScheme } from '../../lib/colors.ts';
1616
import { formatObjectForLog } from '../../lib/pr-cli/debug.ts';
1717
import { chooseMultipleFormatted } from '../../lib/pr-cli/choose.ts';
18-
import { assertValidTitle, writeTitle } from '../../lib/pr-cli/pr-title.ts';
18+
import { assertValidTitle, selectTitle } from '../../lib/pr-cli/pr-title.ts';
1919
import { generatePullRequestBody, replacePRCLIPartOfBody } from '../../lib/pr-cli/pr-body.ts';
2020
import { Command } from '@cliffy/command';
2121
import { colors } from '@cliffy/ansi/colors';
@@ -102,7 +102,7 @@ export const pickCommand = new Command()
102102
throw new Error('No commits chosen');
103103
}
104104

105-
const title = options.title ?? await writeTitle({
105+
const title = options.title ?? await selectTitle({
106106
branchName: options.branch, // This option is only shown if branch was pre-provided
107107
commits: pickedCommits,
108108
});

commands/pick/steps/confirm-settings.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getKeySequence } from '../../../lib/keypress.ts';
55
import { Git } from '../../../lib/git/git.ts';
66
import type { GumStyleOptions } from '../../../lib/gum/style/style.ts';
77
import { chooseOne } from '../../../lib/pr-cli/choose.ts';
8-
import { writeTitle } from '../../../lib/pr-cli/pr-title.ts';
8+
import { editTitle, selectTitle } from '../../../lib/pr-cli/pr-title.ts';
99
import { writePullRequestBody } from '../../../lib/pr-cli/pr-body.ts';
1010
import { CommandExecutionError } from '../../../lib/shell/command-execution-error.ts';
1111
import { colors } from '@cliffy/ansi/colors';
@@ -263,7 +263,12 @@ async function listenForKeySequence(
263263
// Title
264264
't': async (settings: GitPickSettings) => ({
265265
...settings,
266-
title: await writeTitle({
266+
title: await editTitle(settings.title),
267+
}),
268+
// Title
269+
'ctrl+t': async (settings: GitPickSettings) => ({
270+
...settings,
271+
title: await selectTitle({
267272
commits: settings.commits,
268273
branchName: settings.branchName,
269274
currentTitle: settings.title,

commands/pull-request/pull-request-command.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as log from '@std/log';
33
import { Git } from '../../lib/git/git.ts';
44
import { getPullRemote, getPushRemote } from '../../lib/pr-cli/remotes.ts';
55
import { checkDependencies } from '../pick/steps/check-dependencies.ts';
6-
import { writeTitle } from '../../lib/pr-cli/pr-title.ts';
6+
import { selectTitle } from '../../lib/pr-cli/pr-title.ts';
77
import { generatePullRequestBody } from '../../lib/pr-cli/pr-body.ts';
88
import { getDefaultBranch } from '../../lib/pr-cli/branch.ts';
99
import { Command } from '@cliffy/command';
@@ -50,7 +50,7 @@ export const pullRequestCommand = new Command()
5050
throw new Error('No new commit on this branch');
5151
}
5252

53-
options.title ??= await writeTitle({ commits: newCommits, branchName });
53+
options.title ??= await selectTitle({ commits: newCommits, branchName });
5454
if (!options.title) {
5555
throw new Error('Pull request title is empty');
5656
}

lib/pr-cli/pr-title.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type TitleStrategy = {
1515
execute: () => Promise<string> | string;
1616
};
1717

18-
export async function writeTitle(context: TitleContext): Promise<string> {
18+
export async function selectTitle(context: TitleContext): Promise<string> {
1919
const manualStrategy = getManualStrategy(context.currentTitle);
2020
const options: readonly TitleStrategy[] = [
2121
context.commits ? getCommitStrategy(context.commits) : null,
@@ -32,7 +32,11 @@ export async function writeTitle(context: TitleContext): Promise<string> {
3232
},
3333
);
3434

35-
return chosenOption.execute();
35+
return await chosenOption.execute();
36+
}
37+
38+
export async function editTitle(currentTitle: string): Promise<string> {
39+
return await getManualStrategy(currentTitle).execute();
3640
}
3741

3842
function getCommitStrategy(commits: Commit[]): TitleStrategy {

0 commit comments

Comments
 (0)