fix: match quick open backslash path queries (#4123)
This commit is contained in:
@@ -108,8 +108,8 @@ describe('quick-open-search', () => {
|
||||
},
|
||||
{
|
||||
path: 'legacy\\provider\\raw-path.ts',
|
||||
lowerPath: 'legacy\\provider\\raw-path.ts',
|
||||
lowerFilename: 'legacy\\provider\\raw-path.ts',
|
||||
lowerPath: 'legacy/provider/raw-path.ts',
|
||||
lowerFilename: 'raw-path.ts',
|
||||
inputIndex: 3
|
||||
}
|
||||
])
|
||||
@@ -121,4 +121,17 @@ describe('quick-open-search', () => {
|
||||
expect(rankQuickOpenFiles('a', files, 0)).toEqual([])
|
||||
expect(rankQuickOpenFiles('a', files, -1)).toEqual([])
|
||||
})
|
||||
|
||||
it('matches Windows-style path queries against slash-normalized file paths', () => {
|
||||
const files = prepareQuickOpenFiles([
|
||||
'src/components/Button.tsx',
|
||||
'src/components/ButtonGroup.tsx',
|
||||
'src/routes/About.tsx'
|
||||
])
|
||||
|
||||
expect(rankQuickOpenFiles('src\\components\\button', files).map((item) => item.path)).toEqual([
|
||||
'src/components/Button.tsx',
|
||||
'src/components/ButtonGroup.tsx'
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -14,11 +14,12 @@ export type QuickOpenSearchResult = {
|
||||
|
||||
export function prepareQuickOpenFiles(files: readonly string[]): QuickOpenIndexedFile[] {
|
||||
return files.map((path, inputIndex) => {
|
||||
const lastSlash = path.lastIndexOf('/')
|
||||
const searchPath = path.replace(/\\/g, '/')
|
||||
const lastSlash = searchPath.lastIndexOf('/')
|
||||
return {
|
||||
path,
|
||||
lowerPath: path.toLowerCase(),
|
||||
lowerFilename: path.slice(lastSlash + 1).toLowerCase(),
|
||||
lowerPath: searchPath.toLowerCase(),
|
||||
lowerFilename: searchPath.slice(lastSlash + 1).toLowerCase(),
|
||||
inputIndex
|
||||
}
|
||||
})
|
||||
@@ -33,7 +34,9 @@ export function rankQuickOpenFiles(
|
||||
return []
|
||||
}
|
||||
|
||||
const normalizedQuery = query.trim().toLowerCase()
|
||||
// Why: Quick Open presents slash-normalized paths even on Windows; users
|
||||
// still naturally type backslashes in path queries.
|
||||
const normalizedQuery = query.trim().replace(/\\/g, '/').toLowerCase()
|
||||
if (!normalizedQuery) {
|
||||
return files.slice(0, limit).map((file) => ({ path: file.path, score: 0 }))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user