From 814099493fe626e620c0bfd504a7b0b46dacb1ff Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 8 Mar 2022 11:15:10 +0100 Subject: [PATCH 1/2] don't use look behinds --- libs/remix-ui/search/src/lib/context/context.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index e8ce76e287..c6d36532e6 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -208,11 +208,11 @@ export const SearchProvider = ({ const files = await getDirectory('/', plugin) const pathFilter: any = {} if (state.include){ - const includeWithGlobalExpression = state.include.replaceAll(/(? i.trim()) } if (state.exclude){ - const excludeWithGlobalExpression = state.exclude.replaceAll(/(? i.trim()) } const filteredFiles = files.filter(filePathFilter(pathFilter)).map(file => { From 39b07226d758dd441b04fd11ee4094ab7163d329 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 10 Mar 2022 11:20:11 +0100 Subject: [PATCH 2/2] fix regex --- .../search/src/lib/context/context.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index c6d36532e6..bbc3c72795 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -202,18 +202,28 @@ export const SearchProvider = ({ } }, []) + //*.sol, **/*.txt, contracts/* + const setGlobalExpression = (paths: string) => { + const results = [] + paths.split(',').forEach(path => { + path = path.trim() + if(path.startsWith('*.')) path = path.replace(/(\*\.)/g, '**/*.') + if(path.endsWith('/*') && !path.endsWith('/**/*')) path = path.replace(/(\*)/g, '**/*.*') + results.push(path) + }) + return results + } + useEffect(() => { if (state.find) { (async () => { const files = await getDirectory('/', plugin) const pathFilter: any = {} if (state.include){ - const includeWithGlobalExpression = state.include.replaceAll(/(\*\.)/g, '**/*.') - pathFilter.include = includeWithGlobalExpression.split(',').map(i => i.trim()) + pathFilter.include = setGlobalExpression(state.include) } if (state.exclude){ - const excludeWithGlobalExpression = state.exclude.replaceAll(/(\*\.)/g, '**/*.') - pathFilter.exclude = excludeWithGlobalExpression.split(',').map(i => i.trim()) + pathFilter.exclude = setGlobalExpression(state.exclude) } const filteredFiles = files.filter(filePathFilter(pathFilter)).map(file => { const r: SearchResult = {