fix: Crash with some find characters

fix: Warning on close of find dialog
This commit is contained in:
Tom Moor
2023-08-03 19:32:09 -04:00
parent b691311f88
commit 7c15d03b50
2 changed files with 10 additions and 1 deletions

View File

@@ -29,6 +29,7 @@ type Props = {
export default function FindAndReplace({ readOnly }: Props) {
const editor = useEditor();
const finalFocusRef = React.useRef<HTMLElement>(editor.view.dom);
const selectionRef = React.useRef<string | undefined>();
const inputRef = React.useRef<HTMLInputElement>(null);
const { t } = useTranslation();
@@ -224,6 +225,7 @@ export default function FindAndReplace({ readOnly }: Props) {
<Portal>
<Popover
{...popover}
unstable_finalFocusRef={finalFocusRef}
style={style}
aria-label={t("Find and replace")}
width={420}

View File

@@ -141,7 +141,14 @@ export default class FindAndReplace extends Extension {
}
private get findRegExp() {
return RegExp(this.searchTerm, !this.options.caseSensitive ? "gui" : "gu");
try {
return RegExp(
this.searchTerm.replace(/\\+$/, ""),
!this.options.caseSensitive ? "gui" : "gu"
);
} catch (err) {
return RegExp("");
}
}
private goToMatch(direction: number): Command {