From 0db0a565b78ab02fa535e78246091b43fe700a42 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Fri, 30 Dec 2022 23:51:39 +0000 Subject: [PATCH] Desktop: Fixes #7499: Random crash when searching --- .../NoteBody/CodeMirror/utils/useEditorSearch.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.ts b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.ts index 6f55cb58eb..71e20dd51f 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.ts +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useEditorSearch.ts @@ -1,5 +1,8 @@ import { useEffect, useRef, useState } from 'react'; import shim from '@joplin/lib/shim'; +import Logger from '@joplin/lib/Logger'; + +const logger = Logger.create('useEditorSearch'); export default function useEditorSearch(CodeMirror: any) { @@ -23,7 +26,16 @@ export default function useEditorSearch(CodeMirror: any) { function clearOverlay(cm: any) { if (overlay) cm.removeOverlay(overlay); - if (scrollbarMarks) scrollbarMarks.clear(); + if (scrollbarMarks) { + try { + scrollbarMarks.clear(); + } catch (error) { + // This can randomly crash the app so just print a warning since + // it's probably not critical. + // https://github.com/laurent22/joplin/issues/7499 + logger.error('useEditorSearch: Could not clear scrollbar marks:', error); + } + } if (overlayTimeout) shim.clearTimeout(overlayTimeout);