Skip to content

Commit 27fadd5

Browse files
committed
Add close buttons and cancel handling to quick picks and enable opening commits in remote repositories
- revert all those lint fixes [Changes] - on a quick pick with commits, should use 'globe' icon to open them on remote (if available) - on the commits quick pick - place close button in top right corner, prevent outside clicks, when clicking globe - change highllight on the item. - 'close' on commits should not go back to the list of symbols but completely close the flow - all nested symbol quick picks should have close button, not just 'commits' - 'close' button on symbols > skills should completely close, not go back └── apps └── editor └── src ├── commands │ ├── apply-response-command │ │ ├── response-processor │ │ │ ├── handlers │ │ │ │ ├── patch-repair-handler.ts │ │ │ │ └── search-replace-handler.ts │ │ │ └── response-processor.ts │ │ └── utils │ │ ├── file-operations │ │ │ ├── prepare-rename-operation.ts │ │ │ └── read-rename-source-file.ts │ │ └── preview │ │ ├── build-history-files.ts │ │ ├── file-preparer.ts │ │ └── vscode-ui.ts │ ├── copy-merge-commit-details-command.ts │ ├── new-folder-command.ts │ ├── search-files-commands │ │ └── utils │ │ └── get-target-folder-path.ts │ ├── select-files-of-commit-command.ts │ └── set-ranges-command.ts ├── constants │ └── state-keys.ts ├── features │ └── search-files │ └── utils │ └── analyze-files.ts ├── i18n │ ├── index.ts │ └── translations │ ├── common.ts │ └── views │ ├── index.ts │ └── shared │ ├── index.ts │ └── utils │ ├── hash-sign-quick-pick.ts │ └── index.ts ├── services │ └── websocket-manager.ts ├── utils │ ├── agentic-cli-invocation │ │ ├── invoke-agentic-cli.ts │ │ └── utils │ │ └── check-command-exists.ts │ ├── git-repository-utils.ts │ └── path-sanitizer.ts └── views ├── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-hash-sign-quick-pick.ts │ │ │ ├── handle-paste-url.ts │ │ │ ├── handle-preview-generated-code.ts │ │ │ └── utils │ │ │ └── build-cli-prompt.ts │ │ ├── prompt-view-provider.ts │ │ └── utils │ │ ├── persistent-text-storage.ts │ │ ├── preview-text-in-temp-file.ts │ │ ├── symbols │ │ │ ├── fragment │ │ │ │ └── replace-fragment-symbol.ts │ │ │ ├── image │ │ │ │ └── replace-image-symbol.ts │ │ │ ├── pasted-text │ │ │ │ └── replace-pasted-text-symbol.ts │ │ │ └── website │ │ │ └── replace-website-symbol.ts │ │ └── website-fetcher.ts │ ├── frontend │ │ └── Main │ │ └── Main.tsx │ └── types │ └── messages.ts ├── settings │ ├── backend │ │ ├── message-handlers │ │ │ ├── add-provider │ │ │ │ └── pick-extended-provider.ts │ │ │ ├── handle-hash-sign-quick-pick.ts │ │ │ ├── handle-open-allow-patterns-settings.ts │ │ │ └── handle-open-ignore-patterns-settings.ts │ │ └── settings-view-provider.ts │ ├── frontend │ │ └── forms │ │ └── EditPromptInstructionForm │ │ └── EditPromptInstructionForm.tsx │ └── types │ └── messages.ts └── shared └── utils └── hash-sign-quick-pick ├── hash-sign-quick-pick.ts ├── index.ts └── symbols ├── changes-symbol.ts ├── commit-symbol.ts ├── index.ts ├── saved-context-symbol.ts ├── skill-symbol.ts └── snippet-symbol.ts
1 parent c2a7e13 commit 27fadd5

6 files changed

Lines changed: 204 additions & 21 deletions

File tree

‎apps/editor/src/i18n/translations/views/shared/utils/hash-sign-quick-pick.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ export const translations = {
129129
hu: 'Commitok',
130130
bg: 'Къмити'
131131
},
132+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.open-on-remote': {
133+
en: 'Open on remote',
134+
pl: 'Otwórz w zdalnym repozytorium',
135+
'zh-cn': '在远程打开',
136+
ja: 'リモートで開く',
137+
'zh-tw': '在遠程打開',
138+
de: 'Auf Remote öffnen',
139+
es: 'Abrir en remoto',
140+
fr: 'Ouvrir sur le distant',
141+
'pt-br': 'Abrir no remoto',
142+
ru: 'Открыть в удаленном репозитории',
143+
ko: '원격에서 열기',
144+
it: 'Apri in remoto',
145+
tr: 'Uzaktaki depoda aç',
146+
cs: 'Otevřít na vzdáleném serveru',
147+
hu: 'Megnyitás távoli tárolón',
148+
bg: 'Отваряне в отдалечено хранилище'
149+
},
132150
'views.shared.utils.hash-sign-quick-pick.commit-symbol.diff-with-message': {
133151
en: 'Diff with commit message',
134152
pl: 'Różnica z wiadomością commita',

‎apps/editor/src/views/shared/utils/hash-sign-quick-pick/symbols/changes-symbol.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ const execFileAsync = promisify(execFile)
1212
export const handle_changes_item = async (
1313
extension_context: vscode.ExtensionContext
1414
): Promise<string | 'continue' | undefined> => {
15+
const close_button = {
16+
iconPath: new vscode.ThemeIcon('close'),
17+
tooltip: t('common.close')
18+
}
19+
1520
try {
1621
const workspace_folders = vscode.workspace.workspaceFolders
1722
if (!workspace_folders || workspace_folders.length === 0) {
@@ -74,7 +79,7 @@ export const handle_changes_item = async (
7479
quick_pick.items = folder_items
7580
quick_pick.placeholder = 'Select a repository'
7681
quick_pick.title = 'Repositories'
77-
quick_pick.buttons = [vscode.QuickInputButtons.Back]
82+
quick_pick.buttons = [vscode.QuickInputButtons.Back, close_button]
7883

7984
const last_repo = extension_context.workspaceState.get<string>(
8085
LAST_SELECTED_REPOSITORY_IN_SYMBOLS_QUCK_PICK_STATE_KEY
@@ -97,6 +102,9 @@ export const handle_changes_item = async (
97102
did_trigger_back = true
98103
quick_pick.hide()
99104
resolve('back')
105+
} else if (button === close_button) {
106+
quick_pick.hide()
107+
resolve(undefined)
100108
}
101109
}),
102110
quick_pick.onDidAccept(() => {
@@ -115,7 +123,8 @@ export const handle_changes_item = async (
115123
quick_pick.show()
116124
})
117125

118-
if (!picked_folder || picked_folder === 'back') return 'continue'
126+
if (picked_folder === 'back') return 'continue'
127+
if (!picked_folder) return undefined
119128

120129
await extension_context.workspaceState.update(
121130
LAST_SELECTED_REPOSITORY_IN_SYMBOLS_QUCK_PICK_STATE_KEY,
@@ -153,7 +162,7 @@ export const handle_changes_item = async (
153162
quick_pick.items = branch_items
154163
quick_pick.placeholder = 'Select branch to compare with'
155164
quick_pick.title = 'Branches'
156-
quick_pick.buttons = [vscode.QuickInputButtons.Back]
165+
quick_pick.buttons = [vscode.QuickInputButtons.Back, close_button]
157166

158167
const cwd = selected_workspace.folder.uri.fsPath
159168
const folder_name = selected_workspace.folder.name
@@ -248,6 +257,9 @@ export const handle_changes_item = async (
248257
did_trigger_back = true
249258
quick_pick.hide()
250259
resolve('back')
260+
} else if (button === close_button) {
261+
quick_pick.hide()
262+
resolve(undefined)
251263
}
252264
}),
253265
quick_pick.onDidAccept(() => {
@@ -268,13 +280,16 @@ export const handle_changes_item = async (
268280

269281
is_active = false
270282

271-
if (!selected_branch || selected_branch === 'back') {
283+
if (selected_branch === 'back') {
272284
if (workspace_with_branches.length > 1) {
273285
go_back_to_folders = true
274286
break
275287
}
276288
return 'continue'
277289
}
290+
if (!selected_branch) {
291+
return undefined
292+
}
278293

279294
const formatted_branch =
280295
workspace_with_branches.length > 1

‎apps/editor/src/views/shared/utils/hash-sign-quick-pick/symbols/commit-symbol.ts‎

Lines changed: 106 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,49 @@ import { display_token_count } from '@shared/utils/display-token-count'
1010
import { AsciiTree } from '@/utils/ascii-tree/ascii-tree'
1111
import { build_commit_changes_markdown } from '@/views/prompt/backend/utils/symbols/git/replace-git-symbols'
1212

13+
const get_commit_remote_url = (
14+
remote_url: string,
15+
hash: string
16+
): string | undefined => {
17+
if (!remote_url) return undefined
18+
19+
let web_url = remote_url
20+
21+
if (web_url.startsWith('git@')) {
22+
const match = web_url.match(/git@([^:]+):(.+)/)
23+
if (match) {
24+
web_url = `https://${match[1]}/${match[2]}`
25+
}
26+
} else if (web_url.startsWith('ssh://')) {
27+
const match = web_url.match(/ssh:\/\/(?:[^@]+@)?([^/:]+)(?::\d+)?\/(.+)/)
28+
if (match) {
29+
web_url = `https://${match[1]}/${match[2]}`
30+
}
31+
}
32+
33+
if (web_url.endsWith('.git')) {
34+
web_url = web_url.slice(0, -4)
35+
}
36+
37+
if (web_url.includes('bitbucket.org')) {
38+
return `${web_url}/commits/${hash}`
39+
}
40+
if (web_url.includes('gitlab.com') || web_url.includes('gitlab.')) {
41+
return `${web_url}/-/commit/${hash}`
42+
}
43+
return `${web_url}/commit/${hash}`
44+
}
45+
1346
export const handle_commit_item = async (
1447
extension_context: vscode.ExtensionContext,
1548
on_insert: (text: string) => void
1649
): Promise<'continue' | undefined> => {
1750
try {
51+
const close_button = {
52+
iconPath: new vscode.ThemeIcon('close'),
53+
tooltip: t('common.close')
54+
}
55+
1856
const workspace_folders = vscode.workspace.workspaceFolders
1957
if (!workspace_folders || workspace_folders.length === 0) {
2058
vscode.window.showWarningMessage(
@@ -60,7 +98,8 @@ export const handle_commit_item = async (
6098
quick_pick.title = t(
6199
'views.shared.utils.hash-sign-quick-pick.commit-symbol.repositories'
62100
)
63-
quick_pick.buttons = [vscode.QuickInputButtons.Back]
101+
quick_pick.buttons = [vscode.QuickInputButtons.Back, close_button]
102+
quick_pick.ignoreFocusOut = true
64103

65104
const last_repo = extension_context.workspaceState.get<string>(
66105
LAST_SELECTED_REPOSITORY_IN_SYMBOLS_QUCK_PICK_STATE_KEY
@@ -83,6 +122,9 @@ export const handle_commit_item = async (
83122
did_trigger_back = true
84123
quick_pick.hide()
85124
resolve('back')
125+
} else if (button === close_button) {
126+
quick_pick.hide()
127+
resolve(undefined)
86128
}
87129
}),
88130
quick_pick.onDidAccept(() => {
@@ -101,7 +143,8 @@ export const handle_commit_item = async (
101143
quick_pick.show()
102144
})
103145

104-
if (!picked_folder || picked_folder === 'back') return 'continue'
146+
if (picked_folder === 'back') return 'continue'
147+
if (!picked_folder) return undefined
105148

106149
await extension_context.workspaceState.update(
107150
LAST_SELECTED_REPOSITORY_IN_SYMBOLS_QUCK_PICK_STATE_KEY,
@@ -142,14 +185,40 @@ export const handle_commit_item = async (
142185
return 'continue'
143186
}
144187

188+
let remote_url: string | undefined
189+
try {
190+
remote_url = execFileSync(
191+
'git',
192+
['config', '--get', 'remote.origin.url'],
193+
{ cwd: selected_folder.uri.fsPath, encoding: 'utf-8' }
194+
).trim()
195+
} catch {
196+
// ignore
197+
}
198+
145199
const commits_raw = log_output.trim().split('\n')
146200
const commit_items: vscode.QuickPickItem[] = []
147201
for (let i = 0; i < commits_raw.length; i += 3) {
148202
const hash = commits_raw[i]
149203
const message = commits_raw[i + 1] || ''
150204
const date = commits_raw[i + 2] || ''
151205
if (hash) {
152-
commit_items.push({ label: hash, detail: message, description: date })
206+
const item: vscode.QuickPickItem = {
207+
label: hash,
208+
detail: message,
209+
description: date
210+
}
211+
if (remote_url) {
212+
item.buttons = [
213+
{
214+
iconPath: new vscode.ThemeIcon('globe'),
215+
tooltip: t(
216+
'views.shared.utils.hash-sign-quick-pick.commit-symbol.open-on-remote'
217+
)
218+
}
219+
]
220+
}
221+
commit_items.push(item)
153222
}
154223
}
155224

@@ -165,7 +234,8 @@ export const handle_commit_item = async (
165234
quick_pick.title = t(
166235
'views.shared.utils.hash-sign-quick-pick.commit-symbol.commits'
167236
)
168-
quick_pick.buttons = [vscode.QuickInputButtons.Back]
237+
quick_pick.buttons = [vscode.QuickInputButtons.Back, close_button]
238+
quick_pick.ignoreFocusOut = true
169239
quick_pick.matchOnDetail = true
170240

171241
if (last_selected_commit) {
@@ -190,6 +260,22 @@ export const handle_commit_item = async (
190260
did_trigger_back = true
191261
quick_pick.hide()
192262
resolve('back')
263+
} else if (button === close_button) {
264+
quick_pick.hide()
265+
resolve(undefined)
266+
}
267+
}),
268+
quick_pick.onDidTriggerItemButton(async (e) => {
269+
quick_pick.activeItems = [e.item]
270+
if (
271+
e.button.iconPath instanceof vscode.ThemeIcon &&
272+
e.button.iconPath.id === 'globe' &&
273+
remote_url
274+
) {
275+
const url = get_commit_remote_url(remote_url, e.item.label)
276+
if (url) {
277+
await vscode.env.openExternal(vscode.Uri.parse(url))
278+
}
193279
}
194280
}),
195281
quick_pick.onDidAccept(() => {
@@ -208,7 +294,10 @@ export const handle_commit_item = async (
208294
quick_pick.show()
209295
})
210296

211-
if (!selected_commit || selected_commit === 'back') {
297+
if (!selected_commit) {
298+
return undefined
299+
}
300+
if (selected_commit === 'back') {
212301
if (git_folders.length > 1) {
213302
go_back_to_folders = true
214303
break
@@ -308,7 +397,11 @@ export const handle_commit_item = async (
308397
action_quick_pick.title = t(
309398
'views.shared.utils.hash-sign-quick-pick.commit-symbol.options'
310399
)
311-
action_quick_pick.buttons = [vscode.QuickInputButtons.Back]
400+
action_quick_pick.buttons = [
401+
vscode.QuickInputButtons.Back,
402+
close_button
403+
]
404+
action_quick_pick.ignoreFocusOut = true
312405

313406
const last_action = extension_context.workspaceState.get<string>(
314407
LAST_SELECTED_COMMIT_REFERENCE_ACTION_STATE_KEY
@@ -331,6 +424,9 @@ export const handle_commit_item = async (
331424
did_trigger_back = true
332425
action_quick_pick.hide()
333426
resolve('back')
427+
} else if (button === close_button) {
428+
action_quick_pick.hide()
429+
resolve(undefined)
334430
}
335431
}),
336432
action_quick_pick.onDidAccept(() => {
@@ -349,7 +445,10 @@ export const handle_commit_item = async (
349445
action_quick_pick.show()
350446
})
351447

352-
if (!selected_action || selected_action === 'back') {
448+
if (!selected_action) {
449+
return undefined
450+
}
451+
if (selected_action === 'back') {
353452
continue
354453
}
355454

‎apps/editor/src/views/shared/utils/hash-sign-quick-pick/symbols/saved-context-symbol.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import { LAST_SELECTED_CONTEXT_SOURCE_IN_SYMBOLS_QUICK_PICK_STATE_KEY } from '@/
1010
export const handle_saved_context_item = async (
1111
extension_context: vscode.ExtensionContext
1212
): Promise<string | 'continue' | undefined> => {
13+
const close_button = {
14+
iconPath: new vscode.ThemeIcon('close'),
15+
tooltip: t('common.close')
16+
}
17+
1318
try {
1419
const workspace_folders = vscode.workspace.workspaceFolders || []
1520
if (workspace_folders.length === 0) {
@@ -58,7 +63,7 @@ export const handle_saved_context_item = async (
5863
quick_pick.items = source_options
5964
quick_pick.placeholder = 'Select context source'
6065
quick_pick.title = 'Context Sources'
61-
quick_pick.buttons = [vscode.QuickInputButtons.Back]
66+
quick_pick.buttons = [vscode.QuickInputButtons.Back, close_button]
6267

6368
const last_source = extension_context.workspaceState.get<string>(
6469
LAST_SELECTED_CONTEXT_SOURCE_IN_SYMBOLS_QUICK_PICK_STATE_KEY
@@ -85,6 +90,9 @@ export const handle_saved_context_item = async (
8590
did_trigger_back = true
8691
quick_pick.hide()
8792
resolve('back')
93+
} else if (button === close_button) {
94+
quick_pick.hide()
95+
resolve(undefined)
8896
}
8997
}),
9098
quick_pick.onDidAccept(() => {
@@ -103,7 +111,8 @@ export const handle_saved_context_item = async (
103111
quick_pick.show()
104112
})
105113

106-
if (!selection || selection === 'back') return 'continue'
114+
if (selection === 'back') return 'continue'
115+
if (!selection) return undefined
107116

108117
await extension_context.workspaceState.update(
109118
LAST_SELECTED_CONTEXT_SOURCE_IN_SYMBOLS_QUICK_PICK_STATE_KEY,
@@ -162,7 +171,7 @@ export const handle_saved_context_item = async (
162171
quick_pick.items = context_items
163172
quick_pick.placeholder = 'Select a saved context'
164173
quick_pick.title = 'Saved Contexts'
165-
quick_pick.buttons = [vscode.QuickInputButtons.Back]
174+
quick_pick.buttons = [vscode.QuickInputButtons.Back, close_button]
166175

167176
const selected_context = await new Promise<
168177
vscode.QuickPickItem | 'back' | undefined
@@ -177,6 +186,9 @@ export const handle_saved_context_item = async (
177186
did_trigger_back = true
178187
quick_pick.hide()
179188
resolve('back')
189+
} else if (button === close_button) {
190+
quick_pick.hide()
191+
resolve(undefined)
180192
}
181193
}),
182194
quick_pick.onDidAccept(() => {
@@ -195,12 +207,15 @@ export const handle_saved_context_item = async (
195207
quick_pick.show()
196208
})
197209

198-
if (!selected_context || selected_context === 'back') {
210+
if (selected_context === 'back') {
199211
if (source_options.length > 1) {
200212
continue
201213
}
202214
return 'continue'
203215
}
216+
if (!selected_context) {
217+
return undefined
218+
}
204219

205220
if (selected_context) {
206221
const escaped_label = selected_context.label

0 commit comments

Comments
 (0)