Skip to content

Commit eb55d74

Browse files
committed
Preserve files outside search folder when merging context with keyword search results
1 parent fc627b4 commit eb55d74

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

‎packages/vscode/src/commands/keyword-search-in-folder.ts‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,25 @@ export const keyword_search_in_folder_command = (
198198

199199
const selected_paths = selected_items.map((item) => item.file_path)
200200
const currently_checked = workspace_provider.get_checked_files()
201-
let paths_to_apply = selected_paths
202201

203-
if (currently_checked.length > 0) {
202+
const files_outside_search_folder = currently_checked.filter((file) => {
203+
const relative = path.relative(folder_path, file)
204+
return relative.startsWith('..') || path.isAbsolute(relative)
205+
})
206+
207+
let paths_to_apply = [...files_outside_search_folder, ...selected_paths]
208+
209+
const files_inside_search_folder = currently_checked.filter((file) => {
210+
const relative = path.relative(folder_path, file)
211+
return !relative.startsWith('..') && !path.isAbsolute(relative)
212+
})
213+
214+
if (files_inside_search_folder.length > 0) {
204215
const selected_paths_set = new Set(selected_paths)
205-
const all_current_files_in_new_context = currently_checked.every(
206-
(file) => selected_paths_set.has(file)
207-
)
216+
const all_current_files_in_new_context =
217+
files_inside_search_folder.every((file) =>
218+
selected_paths_set.has(file)
219+
)
208220

209221
if (!all_current_files_in_new_context) {
210222
const quick_pick_options = [
@@ -274,7 +286,9 @@ export const keyword_search_in_folder_command = (
274286

275287
await workspace_provider.set_checked_files(paths_to_apply)
276288
vscode.window.showInformationMessage(
277-
dictionary.information_message.SELECTED_FILES(paths_to_apply.length)
289+
dictionary.information_message.SELECTED_FILES(
290+
paths_to_apply.length - files_outside_search_folder.length
291+
)
278292
)
279293
} catch (error) {
280294
vscode.window.showErrorMessage(

0 commit comments

Comments
 (0)