Skip to content

Commit 5349d50

Browse files
committed
Sync workspace selections during preview workflows and reset default checkbox states for new workspace items
- newly created item in fully checked folder should not be checked by default - when 'apply response' creates a file in a previously fully checked folder, it's still 'checked', even if it now has an unchecked file (until we accept) └── apps └── editor └── src ├── commands │ └── apply-response-command │ ├── apply-response-command.ts │ ├── response-processor │ │ ├── handlers │ │ │ ├── diff-handler.ts │ │ │ └── fast-replace-handler.ts │ │ └── response-processor.ts │ └── utils │ ├── preview │ │ ├── preview.ts │ │ └── workspace-listener.ts │ └── preview-handler.ts └── context ├── context-initialization.ts ├── helpers │ ├── get-all-workspace-files.ts │ └── get-selected-files.ts ├── providers │ ├── open-editors │ │ └── open-editors-provider.ts │ ├── selected-files │ │ └── selected-files-provider.ts │ └── workspace │ ├── modules │ │ ├── index.ts │ │ └── token-calculator.ts │ └── workspace-provider.ts └── shared-context-state.ts
1 parent 717738e commit 5349d50

2 files changed

Lines changed: 89 additions & 17 deletions

File tree

‎apps/editor/src/commands/apply-response-command/utils/preview-handler.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export const preview_handler = async (params: {
4545
})
4646

4747
try {
48+
await sync_workspace_selection_for_states({
49+
workspace_provider: params.workspace_provider,
50+
states: params.original_states
51+
})
52+
4853
const preview_result = await preview({
4954
original_states: params.original_states,
5055
prompt_view_provider: params.prompt_view_provider,
@@ -101,6 +106,10 @@ export const preview_handler = async (params: {
101106
await undo_files({
102107
original_states: params.original_states
103108
})
109+
await sync_workspace_selection_for_states({
110+
workspace_provider: params.workspace_provider,
111+
states: params.original_states
112+
})
104113
} finally {
105114
params.workspace_provider.resume_file_watcher()
106115
}
@@ -118,6 +127,10 @@ export const preview_handler = async (params: {
118127
await undo_files({
119128
original_states: preview_result.rejected_states
120129
})
130+
await sync_workspace_selection_for_states({
131+
workspace_provider: params.workspace_provider,
132+
states: preview_result.rejected_states
133+
})
121134
} finally {
122135
params.workspace_provider.resume_file_watcher()
123136
}
@@ -266,3 +279,33 @@ export const preview_handler = async (params: {
266279
ongoing_preview_cleanup_promise = null
267280
}
268281
}
282+
283+
const sync_workspace_selection_for_states = async (params: {
284+
workspace_provider: WorkspaceProvider
285+
states: OriginalFileState[]
286+
}) => {
287+
const { workspace_map, default_workspace } = get_workspace_map_and_default()
288+
const paths = new Set<string>()
289+
290+
const add = (file_path?: string, workspace_name?: string) => {
291+
if (!file_path) return
292+
if (path.isAbsolute(file_path)) {
293+
paths.add(file_path)
294+
return
295+
}
296+
const root = resolve_workspace_root({
297+
workspace_name,
298+
workspace_map,
299+
default_workspace
300+
})
301+
if (root) paths.add(path.join(root, file_path))
302+
}
303+
304+
for (const state of params.states) {
305+
add(state.file_path, state.workspace_name)
306+
add(state.new_file_path, state.new_workspace_name ?? state.workspace_name)
307+
add(state.file_path_to_restore, state.restore_workspace_name)
308+
}
309+
310+
await params.workspace_provider.sync_externally_changed_paths([...paths])
311+
}

‎apps/editor/src/context/providers/workspace/workspace-provider.ts‎

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -491,17 +491,13 @@ export class WorkspaceProvider
491491

492492
this._checked_items.set(
493493
created_file_path,
494-
vscode.TreeItemCheckboxState.Checked
495-
)
496-
this._selected_timestamps.set(
497-
created_file_path,
498-
Math.floor(Date.now() / 1000)
494+
vscode.TreeItemCheckboxState.Unchecked
499495
)
500496

501497
if (is_directory) {
502498
await this._update_directory_checkbox_state(
503499
created_file_path,
504-
vscode.TreeItemCheckboxState.Checked,
500+
vscode.TreeItemCheckboxState.Unchecked,
505501
false
506502
)
507503
}
@@ -546,6 +542,49 @@ export class WorkspaceProvider
546542
}, 1500)
547543
}
548544

545+
async sync_externally_changed_paths(file_paths: string[]): Promise<void> {
546+
let changed = false
547+
548+
for (const file_path of file_paths) {
549+
const workspace_root = this.get_workspace_root_for_file(file_path)
550+
if (!workspace_root) continue
551+
552+
if (fs.existsSync(file_path)) {
553+
if (this.is_ignored_by_patterns(file_path)) continue
554+
const relative_path = path.relative(workspace_root, file_path)
555+
if (this.is_excluded(relative_path)) continue
556+
557+
this._file_workspace_map.set(file_path, workspace_root)
558+
if (!this._checked_items.has(file_path)) {
559+
this._checked_items.set(
560+
file_path,
561+
vscode.TreeItemCheckboxState.Unchecked
562+
)
563+
}
564+
} else {
565+
this._file_workspace_map.delete(file_path)
566+
this._checked_items.delete(file_path)
567+
this._selected_timestamps.delete(file_path)
568+
this._partially_selected_dirs.delete(file_path)
569+
}
570+
571+
this._token_calculator.invalidate_token_counts_for_file(file_path)
572+
573+
let dir_path = path.dirname(file_path)
574+
while (dir_path.startsWith(workspace_root)) {
575+
await this._update_parent_state(dir_path)
576+
const next_dir_path = path.dirname(dir_path)
577+
if (next_dir_path === dir_path) break
578+
dir_path = next_dir_path
579+
}
580+
changed = true
581+
}
582+
583+
if (changed) {
584+
this._dispatch_change_events()
585+
}
586+
}
587+
549588
async clear_selected_files(): Promise<void> {
550589
this._checked_items.clear()
551590
this._selected_timestamps.clear()
@@ -934,17 +973,7 @@ export class WorkspaceProvider
934973

935974
let checkbox_state = this._checked_items.get(key)
936975
if (checkbox_state === undefined) {
937-
const parent_path = path.dirname(full_path)
938-
const parent_checkbox_state = this._checked_items.get(parent_path)
939-
if (
940-
parent_checkbox_state === vscode.TreeItemCheckboxState.Checked &&
941-
!is_ignored
942-
) {
943-
checkbox_state = vscode.TreeItemCheckboxState.Checked
944-
this._checked_items.set(full_path, checkbox_state)
945-
} else {
946-
checkbox_state = vscode.TreeItemCheckboxState.Unchecked
947-
}
976+
checkbox_state = vscode.TreeItemCheckboxState.Unchecked
948977
}
949978

950979
const tokens = is_directory

0 commit comments

Comments
 (0)