From f72b356562c571f7e797d1d204bb718f672a0127 Mon Sep 17 00:00:00 2001 From: hkgnp Date: Sun, 6 Feb 2022 18:14:30 +0800 Subject: [PATCH] refactoring --- package.json | 2 +- src/mathliveCustom.ts | 40 ++++++++++++++++------------------------ 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 5cdd8d2..5ada6b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "darwis-mathlive-plugin", - "version": "1.0.5", + "version": "1.0.6", "description": "", "main": "dist/index.html", "targets": { diff --git a/src/mathliveCustom.ts b/src/mathliveCustom.ts index ec3a8f7..81035ea 100644 --- a/src/mathliveCustom.ts +++ b/src/mathliveCustom.ts @@ -27,38 +27,30 @@ export const renderMathLive = ( connectedCallback() { this.render(); - window.setTimeout(() => { - top?.document - .getElementById('container') - .addEventListener('mousedown', async (e) => { - e.stopPropagation(); - e.preventDefault(); - await logseq.Editor.restoreEditingCursor(); - }); + window.setTimeout(async () => { + const formulaDiv = top?.document.getElementById( + `formula-${uniqueIdentifier}` + ); - top?.document - .getElementById('formula') - .addEventListener('input', async (ev) => { - await logseq.Editor.upsertBlockProperty( - uuid, - 'output', - //@ts-expect-error - ev.target.value - ); - }); + formulaDiv.addEventListener('input', async (ev) => { + await logseq.Editor.upsertBlockProperty( + uuid, + 'output', + //@ts-expect-error + ev.target.value + ); + }); - top?.document - .getElementById('formula') - .addEventListener('change', async () => { - await logseq.Editor.restoreEditingCursor(); - }); + formulaDiv.addEventListener('change', async () => { + await logseq.Editor.restoreEditingCursor(); + }); }, 500); } async render() { const output = await logseq.Editor.getBlockProperty(uuid, 'output'); - this.innerHTML = `