diff --git a/src/components/NotePage/NoteList/NoteItem.tsx b/src/components/NotePage/NoteList/NoteItem.tsx
index 52963ac49a..b2057c591c 100644
--- a/src/components/NotePage/NoteList/NoteItem.tsx
+++ b/src/components/NotePage/NoteList/NoteItem.tsx
@@ -9,6 +9,7 @@ import {
} from '../../../lib/styled/styleFunctions'
import cc from 'classcat'
import { setTransferrableNoteData } from '../../../lib/dnd'
+import HighlightText from '../../atoms/HighlightText'
export const StyledNoteListItem = styled.div`
margin: 0;
@@ -76,21 +77,41 @@ type NoteItemProps = {
note: NoteDoc
active: boolean
storageId: string
+ search: string
basePathname: string
focusList: () => void
}
-export default ({ storageId, note, active, basePathname }: NoteItemProps) => {
+export default ({
+ storageId,
+ note,
+ active,
+ basePathname,
+ search
+}: NoteItemProps) => {
const href = `${basePathname}/${note._id}`
const contentPreview = useMemo(() => {
- return (
- note.content
- .trim()
+ const trimmedContent = note.content.trim()
+ const searchFirstIndex = trimmedContent
+ .toLowerCase()
+ .indexOf(search.toLowerCase())
+
+ if (search !== '' && searchFirstIndex !== -1) {
+ const contentToHighlight = trimmedContent
+ .substring(searchFirstIndex)
.split('\n')
- .shift() || 'Empty note'
- )
- }, [note.content])
+ .shift()
+
+ return contentToHighlight == null ? (
+ 'Empty note'
+ ) : (
+