Skip to content

Commit ec1ac46

Browse files
committed
Add action buttons and preserve file selection state in unstaged files quick pick
1 parent 216b0f9 commit ec1ac46

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

apps/editor/src/commands/apply-context-command/sources/unstaged-files-source.ts

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ export const handle_unstaged_files_source = async (
6767
const workspace_roots = workspace_provider.get_workspace_roots()
6868

6969
while (true) {
70+
const currently_checked = workspace_provider.get_checked_files()
71+
const currently_checked_set = new Set(currently_checked)
72+
7073
const quick_pick_items = await Promise.all(
7174
existing_unstaged_files.map(async (file_path) => {
7275
const token_count =
@@ -82,9 +85,23 @@ export const handle_unstaged_files_source = async (
8285

8386
return {
8487
label: path.basename(file_path),
85-
description: `${formatted_token_count} · ${display_dir}`.trim(),
86-
picked: true,
87-
file_path
88+
description: display_dir
89+
? `${formatted_token_count} · ${display_dir}`
90+
: formatted_token_count,
91+
picked: currently_checked_set.has(file_path),
92+
file_path,
93+
buttons: [
94+
{
95+
iconPath: new vscode.ThemeIcon(
96+
'git-pull-request-go-to-changes'
97+
),
98+
tooltip: t('command.commit-message.show-diff')
99+
},
100+
{
101+
iconPath: new vscode.ThemeIcon('go-to-file'),
102+
tooltip: t('common.go-to-file')
103+
}
104+
]
88105
}
89106
})
90107
)
@@ -96,7 +113,8 @@ export const handle_unstaged_files_source = async (
96113
quick_pick.placeholder = t('command.apply-context.unstaged.include')
97114
quick_pick.canSelectMany = true
98115
quick_pick.items = quick_pick_items
99-
quick_pick.selectedItems = quick_pick_items
116+
quick_pick.ignoreFocusOut = true
117+
quick_pick.selectedItems = quick_pick_items.filter((item) => item.picked)
100118
quick_pick.buttons = [vscode.QuickInputButtons.Back]
101119

102120
const selected_items = await new Promise<
@@ -115,6 +133,18 @@ export const handle_unstaged_files_source = async (
115133
}
116134
})
117135

136+
quick_pick.onDidTriggerItemButton(async (e) => {
137+
if (e.button.tooltip == t('common.go-to-file')) {
138+
const uri = vscode.Uri.file(e.item.file_path)
139+
vscode.window.showTextDocument(uri, { preview: true })
140+
} else if (
141+
e.button.tooltip == t('command.commit-message.show-diff')
142+
) {
143+
const uri = vscode.Uri.file(e.item.file_path)
144+
await vscode.commands.executeCommand('git.openChange', uri)
145+
}
146+
})
147+
118148
quick_pick.onDidAccept(() => {
119149
is_accepted = true
120150
resolve(quick_pick.selectedItems)
@@ -140,7 +170,6 @@ export const handle_unstaged_files_source = async (
140170
}
141171

142172
const selected_paths = selected_items.map((item) => item.file_path)
143-
const currently_checked = workspace_provider.get_checked_files()
144173
let paths_to_apply = selected_paths
145174
let should_continue = false
146175

@@ -239,8 +268,15 @@ export const handle_unstaged_files_source = async (
239268
})
240269

241270
await workspace_provider.set_checked_files(paths_to_apply)
271+
272+
const newly_selected_count = selected_paths.filter(
273+
(p) => !currently_checked.includes(p)
274+
).length
275+
242276
vscode.window.showInformationMessage(
243-
dictionary.information_message.SELECTED_FILES(paths_to_apply.length)
277+
dictionary.information_message.ADDED_FILES_TO_CONTEXT(
278+
newly_selected_count
279+
)
244280
)
245281
return
246282
}

packages/shared/src/constants/dictionary.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export const dictionary = {
9191
'No actionable unstaged files found (e.g. only deletions).',
9292
ADDED_FILES_TO_CONTEXT: (count: number) =>
9393
`Added ${count} file${count == 1 ? '' : 's'} to context.`,
94+
SELECTED_FILES: (count: number) =>
95+
`Selected ${count} file${count == 1 ? '' : 's'}.`,
9496
DELETED_CONTEXT_FROM_WORKSPACE_STATE: 'Deleted context.',
9597
CONTEXT_SAVED_SUCCESSFULLY: 'Saved successfully.',
9698
CONTEXT_APPLIED_SUCCESSFULLY: 'Context applied successfully.',

0 commit comments

Comments
 (0)