From 5eaee44daa72196432d00b52a5016ecacc95a1c4 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 24 Sep 2025 06:49:39 -0500 Subject: [PATCH] refac --- .../components/common/RichTextInput.svelte | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lib/components/common/RichTextInput.svelte b/src/lib/components/common/RichTextInput.svelte index 0c46d0f296..b9656954bd 100644 --- a/src/lib/components/common/RichTextInput.svelte +++ b/src/lib/components/common/RichTextInput.svelte @@ -149,10 +149,15 @@ export let onChange = (e) => {}; // create a lowlight instance with all languages loaded - const lowlight = createLowlight(hljs.listLanguages().reduce((obj, lang) => { - obj[lang] = () => hljs.getLanguage(lang); - return obj; - }, {} as Record)); + const lowlight = createLowlight( + hljs.listLanguages().reduce( + (obj, lang) => { + obj[lang] = () => hljs.getLanguage(lang); + return obj; + }, + {} as Record + ) + ); export let editor: Editor | null = null; @@ -501,9 +506,14 @@ export const focus = () => { if (editor) { - editor.view.focus(); - // Scroll to the current selection - editor.view.dispatch(editor.view.state.tr.scrollIntoView()); + try { + editor.view?.focus(); + // Scroll to the current selection + editor.view?.dispatch(editor.view.state.tr.scrollIntoView()); + } catch (e) { + // sometimes focusing throws an error, ignore + console.warn('Error focusing editor', e); + } } };