fix: tag search causing regex exception (#938)

This commit is contained in:
Aman Harwara
2022-03-19 16:40:55 +05:30
committed by GitHub
parent 105c0cdce9
commit 8265d94c86
5 changed files with 200 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
import { AppState } from '@/ui_models/app_state';
import { splitQueryInString } from '@/utils/stringUtils';
import { SNTag } from '@standardnotes/snjs';
import { observer } from 'mobx-react-lite';
import { useEffect, useRef } from 'preact/hooks';
@@ -71,7 +72,7 @@ export const AutocompleteTagResult = observer(
useEffect(() => {
if (focusedTagResultUuid === tagResult.uuid) {
tagResultRef.current!.focus();
tagResultRef.current?.focus();
appState.noteTags.setFocusedTagResultUuid(undefined);
}
}, [appState.noteTags, focusedTagResultUuid, tagResult]);
@@ -92,9 +93,8 @@ export const AutocompleteTagResult = observer(
{prefixTitle && <span className="grey-2">{prefixTitle}</span>}
{autocompleteSearchQuery === ''
? title
: title
.split(new RegExp(`(${autocompleteSearchQuery})`, 'gi'))
.map((substring, index) => (
: splitQueryInString(title, autocompleteSearchQuery).map(
(substring, index) => (
<span
key={index}
className={`${
@@ -106,7 +106,8 @@ export const AutocompleteTagResult = observer(
>
{substring}
</span>
))}
)
)}
</span>
</button>
);