mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Case-insensitive search
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
a6eb28335d
commit
e3a3fb42eb
@ -164,14 +164,18 @@ export class PodLogs extends React.Component<Props> {
|
||||
const { searchQuery, isActiveOverlay } = searchStore;
|
||||
const item = this.logs[rowIndex];
|
||||
const contents: React.ReactElement[] = [];
|
||||
if (searchQuery) {
|
||||
// If search is enabled, replace keyword with backgrounded <span> to "highlight" searchable text
|
||||
const pieces = item.split(searchQuery);
|
||||
if (searchQuery) { // If search is enabled, replace keyword with backgrounded <span>
|
||||
// Case-insensitive search (lowercasing query and keywords in line)
|
||||
const regex = new RegExp(searchStore.escapeRegex(searchQuery), "gi");
|
||||
const matches = item.matchAll(regex);
|
||||
const modified = item.replace(regex, match => match.toLowerCase());
|
||||
// Splitting text line by keyword
|
||||
const pieces = modified.split(searchQuery.toLowerCase());
|
||||
pieces.forEach((piece, index) => {
|
||||
const active = isActiveOverlay(rowIndex, index);
|
||||
const lastItem = index === pieces.length - 1;
|
||||
const overlay = !lastItem ?
|
||||
<span className={cssNames({ active })}>{searchQuery}</span> :
|
||||
<span className={cssNames({ active })}>{matches.next().value}</span> :
|
||||
null
|
||||
contents.push(
|
||||
<React.Fragment key={piece + index}>
|
||||
|
||||
@ -36,7 +36,7 @@ export class SearchStore {
|
||||
findOccurencies(text: string[], query: string) {
|
||||
const occurences: number[] = [];
|
||||
text.forEach((line, index) => {
|
||||
const regex = new RegExp(this.escapeRegex(query), "g");
|
||||
const regex = new RegExp(this.escapeRegex(query), "gi");
|
||||
const matches = [...line.matchAll(regex)];
|
||||
matches.forEach(() => occurences.push(index));
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user