From e3a3fb42ebfa1df4d73ebc84266ef51875eb52c7 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Thu, 22 Oct 2020 12:53:26 +0300 Subject: [PATCH] Case-insensitive search Signed-off-by: Alex Andreev --- src/renderer/components/dock/pod-logs.tsx | 12 ++++++++---- src/renderer/components/dock/search.store.ts | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/renderer/components/dock/pod-logs.tsx b/src/renderer/components/dock/pod-logs.tsx index 7e64b2cd20..66d5e8fb0b 100644 --- a/src/renderer/components/dock/pod-logs.tsx +++ b/src/renderer/components/dock/pod-logs.tsx @@ -164,14 +164,18 @@ export class PodLogs extends React.Component { const { searchQuery, isActiveOverlay } = searchStore; const item = this.logs[rowIndex]; const contents: React.ReactElement[] = []; - if (searchQuery) { - // If search is enabled, replace keyword with backgrounded to "highlight" searchable text - const pieces = item.split(searchQuery); + if (searchQuery) { // If search is enabled, replace keyword with backgrounded + // 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 ? - {searchQuery} : + {matches.next().value} : null contents.push( diff --git a/src/renderer/components/dock/search.store.ts b/src/renderer/components/dock/search.store.ts index bd355e53a3..8f1370ba23 100644 --- a/src/renderer/components/dock/search.store.ts +++ b/src/renderer/components/dock/search.store.ts @@ -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)); });