From 8739ad8a8c6a07ac134048a68209e10521df7adc Mon Sep 17 00:00:00 2001 From: Jeremy Valentine <38669521+valentine195@users.noreply.github.com> Date: Sat, 16 Sep 2023 10:04:55 -0400 Subject: [PATCH] fix: delay live preview focus to allow for click events --- src/main.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main.ts b/src/main.ts index 112c130..2eee23f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -373,14 +373,18 @@ ${editor.getDoc().getSelection()} if (ev.defaultPrevented || ev.detail > 1 || ev.shiftKey) return; try { - const pos = editor.posAtDOM(admonitionElement); - editor.focus(); - editor.dispatch({ - selection: { - head: pos, - anchor: pos - } - }); + setTimeout(() => { + try { + const pos = editor.posAtDOM(admonitionElement); + editor.focus(); + editor.dispatch({ + selection: { + head: pos, + anchor: pos + } + }); + } catch (e) {} + }, 10); } catch (e) {} }); }