1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

allow for regex and wildcard search

Signed-off-by: Luca Kröger <l.kroeger01@gmail.com>
This commit is contained in:
Luca Kröger 2021-06-07 21:10:52 +02:00
parent 60a19143b4
commit 9a83fc6be7

View File

@ -171,7 +171,19 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
return searchFilters.some(getTexts => {
const sourceTexts: string[] = [getTexts(item)].flat().map(normalizeText);
return sourceTexts.some(source => searchTexts.some(search => source.includes(search)));
return searchTexts.some(search => {
if(search.startsWith("regex:")) {
const matcher = new RegExp(search.substring(6).trim());
return sourceTexts.some(source => matcher.test(source));
} else if(search.indexOf("*") !== -1) {
const matcher = new RegExp(search.split("*").map(string => string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*"));
return sourceTexts.some(source => matcher.test(source));
} else {
return sourceTexts.some(source => source.indexOf(search) !== -1);
}
});
});
});
}