Skip to content

Commit 60f1574

Browse files
committed
Skip redundant context application and improve user feedback messages
- after a context is saved, highlight the newly created row - when updating paths, show 'Updated sucessfully', not 'Saved successfully' - update on workspace state works correctly, but update on JSON file - closes quick pick - don't offer merge/replace if the saved context is identical to the current one. - instead of 'context merged successfully' say 'context applied successfully', so we have one message for any type of action - when the current context is identical, don't show confirmation notification - when identical, show 'Context already set.' add to dictionary
1 parent f58e6bf commit 60f1574

6 files changed

Lines changed: 72 additions & 18 deletions

File tree

‎apps/editor/src/commands/apply-context-command/helpers/applying/apply-saved-context.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@ export const apply_saved_context = async (
2828
}
2929

3030
let paths_to_apply = existing_paths
31-
let message = dictionary.information_message.CONTEXT_APPLIED_SUCCESSFULLY
31+
const message = dictionary.information_message.CONTEXT_APPLIED_SUCCESSFULLY
3232

3333
const currently_checked_files = workspace_provider.get_checked_files()
3434
if (currently_checked_files.length > 0) {
3535
const existing_paths_set = new Set(existing_paths)
36-
const all_current_files_in_new_context = currently_checked_files.every(
37-
(file) => existing_paths_set.has(file)
38-
)
36+
const is_identical =
37+
currently_checked_files.length == existing_paths_set.size &&
38+
currently_checked_files.every((file) => existing_paths_set.has(file))
39+
40+
if (is_identical) {
41+
vscode.window.showInformationMessage(
42+
dictionary.information_message.CONTEXT_ALREADY_SET
43+
)
44+
return
45+
}
3946

40-
if (!all_current_files_in_new_context) {
47+
if (!is_identical) {
4148
const quick_pick_options: (vscode.QuickPickItem & {
4249
action_id: string
4350
})[] = [
@@ -117,7 +124,6 @@ export const apply_saved_context = async (
117124
paths_to_apply = [
118125
...new Set([...currently_checked_files, ...existing_paths])
119126
]
120-
message = dictionary.information_message.CONTEXT_MERGED_SUCCESSFULLY
121127
}
122128
}
123129
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,18 @@ export const handle_commit_files_source = async (
159159

160160
if (currently_checked.length > 0) {
161161
const selected_paths_set = new Set(selected_paths)
162-
const all_current_files_in_new_context = currently_checked.every(
163-
(file) => selected_paths_set.has(file)
164-
)
162+
const is_identical =
163+
currently_checked.length == selected_paths_set.size &&
164+
currently_checked.every((file) => selected_paths_set.has(file))
165165

166-
if (!all_current_files_in_new_context) {
166+
if (is_identical) {
167+
vscode.window.showInformationMessage(
168+
dictionary.information_message.CONTEXT_ALREADY_SET
169+
)
170+
return
171+
}
172+
173+
if (!is_identical) {
167174
const quick_pick_options = [
168175
{
169176
label: t('command.apply-context.action.replace.label'),

‎apps/editor/src/commands/apply-context-command/sources/json-file-source.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export const handle_json_file_source = async (
9393
}
9494

9595
let active_dialog_count = 0
96+
let name_to_highlight: string | undefined
9697

9798
while (true) {
9899
const create_items = () => {
@@ -144,6 +145,16 @@ export const handle_json_file_source = async (
144145
quick_pick.placeholder = t('command.apply-context.select-saved.file')
145146
quick_pick.buttons = [vscode.QuickInputButtons.Back, open_file_button]
146147

148+
if (name_to_highlight) {
149+
const active_item = quick_pick.items.find(
150+
(i: any) => i.label == name_to_highlight
151+
)
152+
if (active_item) {
153+
quick_pick.activeItems = [active_item]
154+
}
155+
name_to_highlight = undefined
156+
}
157+
147158
const selection = await new Promise<any>((resolve) => {
148159
let is_resolved = false
149160
const resolve_once = (value: any) => {
@@ -278,9 +289,13 @@ export const handle_json_file_source = async (
278289
await save_contexts_to_file(contexts, p)
279290
}
280291
vscode.window.showInformationMessage(
281-
dictionary.information_message.CONTEXT_SAVED_SUCCESSFULLY
292+
dictionary.information_message.CONTEXT_UPDATED_SUCCESSFULLY
282293
)
283-
return
294+
name_to_highlight = context_name
295+
const reloaded = await load_and_merge_file_contexts()
296+
file_contexts = reloaded.merged
297+
context_to_roots = reloaded.context_to_roots
298+
continue
284299
}
285300

286301
if (selection.triggeredButton === edit_button) {
@@ -326,6 +341,8 @@ export const handle_json_file_source = async (
326341
file_contexts = reloaded.merged
327342
context_to_roots = reloaded.context_to_roots
328343
}
344+
name_to_highlight =
345+
new_name && new_name != old_name ? new_name : old_name
329346
} else if (selection.triggeredButton === delete_button) {
330347
active_dialog_count++
331348
const choice = await vscode.window.showInformationMessage(
@@ -407,6 +424,7 @@ export const handle_json_file_source = async (
407424
const reloaded = await load_and_merge_file_contexts()
408425
file_contexts = reloaded.merged
409426
context_to_roots = reloaded.context_to_roots
427+
name_to_highlight = unique_name
410428
continue
411429
}
412430

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,18 @@ export const handle_unstaged_files_source = async (
175175

176176
if (currently_checked.length > 0) {
177177
const selected_paths_set = new Set(selected_paths)
178-
const all_current_files_in_new_context = currently_checked.every(
179-
(file) => selected_paths_set.has(file)
180-
)
178+
const is_identical =
179+
currently_checked.length == selected_paths_set.size &&
180+
currently_checked.every((file) => selected_paths_set.has(file))
181+
182+
if (is_identical) {
183+
vscode.window.showInformationMessage(
184+
dictionary.information_message.CONTEXT_ALREADY_SET
185+
)
186+
return
187+
}
181188

182-
if (!all_current_files_in_new_context) {
189+
if (!is_identical) {
183190
const quick_pick_options = [
184191
{
185192
label: t('command.apply-context.action.replace.label'),

‎apps/editor/src/commands/apply-context-command/sources/workspace-state-source.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ export const handle_workspace_state_source = async (
192192
internal_contexts = reloaded.merged
193193
context_to_roots = reloaded.context_to_roots
194194
quick_pick.items = create_quick_pick_items(internal_contexts)
195+
const active_item = quick_pick.items.find(
196+
(i) => i.label == unique_name
197+
)
198+
if (active_item) {
199+
quick_pick.activeItems = [active_item]
200+
}
201+
195202
quick_pick.value = ''
196203
quick_pick.show()
197204
return
@@ -273,12 +280,20 @@ export const handle_workspace_state_source = async (
273280
}
274281

275282
vscode.window.showInformationMessage(
276-
dictionary.information_message.CONTEXT_SAVED_SUCCESSFULLY
283+
dictionary.information_message.CONTEXT_UPDATED_SUCCESSFULLY
277284
)
278285
const reloaded = refresh_contexts()
279286
internal_contexts = reloaded.merged
280287
context_to_roots = reloaded.context_to_roots
281288
quick_pick.items = create_quick_pick_items(internal_contexts)
289+
290+
const active_item = quick_pick.items.find(
291+
(i) => i.label === context.name
292+
)
293+
if (active_item) {
294+
quick_pick.activeItems = [active_item]
295+
}
296+
282297
quick_pick.show()
283298
return
284299
}

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export const dictionary = {
4747
CONTEXT_COPIED_TO_CLIPBOARD: 'Context copied to clipboard.',
4848
CONTEXT_FROM_OPEN_EDITORS_COPIED_TO_CLIPBOARD:
4949
'Context from open editors copied to clipboard.',
50+
CONTEXT_ALREADY_SET: 'Context already set.',
51+
CONTEXT_UPDATED_SUCCESSFULLY: 'Updated successfully.',
5052
NO_SAVED_CONTEXTS_FOUND: 'No saved contexts found.',
5153
NO_COMMIT_MESSAGES_CONFIGURATIONS_FOUND:
5254
'No "Commit Messages" configurations found. Please add one in settings.',
@@ -96,7 +98,6 @@ export const dictionary = {
9698
DELETED_CONTEXT_FROM_WORKSPACE_STATE: 'Deleted context.',
9799
CONTEXT_SAVED_SUCCESSFULLY: 'Saved successfully.',
98100
CONTEXT_APPLIED_SUCCESSFULLY: 'Context applied successfully.',
99-
CONTEXT_MERGED_SUCCESSFULLY: 'Context merged successfully.',
100101
FILES_REMAIN_CHECKED: (count: number) =>
101102
`${count} file${count == 1 ? '' : 's'} remain${
102103
count == 1 ? 's' : ''

0 commit comments

Comments
 (0)