Skip to content

Commit d9b4f9b

Browse files
committed
Preserve literal double quotes in phrase search queries
- in 'phrase' search: `"classnames"` should not match `'classnames'` └── apps └── editor └── src └── features └── search-files ├── search-files.ts ├── search-modes │ └── perform-phrase-search-mode.ts └── utils ├── create-search-regex.ts ├── prompt-for-search-mode.ts ├── prompt-for-search-results.ts ├── prompt-for-search-term.ts ├── search-files-by-keywords.ts ├── search-files-by-phrase.ts └── show-search-results-quick-pick.ts
1 parent 2f02746 commit d9b4f9b

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎apps/editor/src/features/search-files/utils/create-search-regex.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
export const create_search_regex = (search_term: string): RegExp => {
1+
export const create_search_regex = (
2+
search_term: string,
3+
options?: { is_phrase_search?: boolean }
4+
): RegExp => {
25
let actual_term = search_term
36
let is_exact_match = false
47

58
if (
9+
!options?.is_phrase_search &&
610
actual_term.length >= 2 &&
711
actual_term.startsWith('"') &&
812
actual_term.endsWith('"')

‎apps/editor/src/features/search-files/utils/search-files-by-phrase.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export const search_files_by_phrase = async (params: {
1313
get_file_content?: (file_path: string) => Promise<string | undefined>
1414
}): Promise<string[]> => {
1515
const matched_files: string[] = []
16-
const positive_regex = create_search_regex(params.search_term)
16+
const positive_regex = create_search_regex(params.search_term, {
17+
is_phrase_search: true
18+
})
1719

1820
let processed = 0
1921
for (const file_path of params.files) {

‎apps/editor/src/features/search-files/utils/show-search-results-quick-pick.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ export const show_search_results_quick_pick = async (params: {
205205
let selection: vscode.Range | undefined
206206
if (params.search_mode === 'phrase' && params.search_term) {
207207
const text = doc.getText()
208-
const regexes = [create_search_regex(params.search_term)]
208+
const regexes = [
209+
create_search_regex(params.search_term, {
210+
is_phrase_search: true
211+
})
212+
]
209213

210214
for (const regex of regexes) {
211215
const match = regex.exec(text)

0 commit comments

Comments
 (0)