Skip to content

Commit

Permalink
fix: avoid inserting delims when LaTeX is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanChain committed Aug 30, 2023
1 parent 9fb97c2 commit 3bcb491
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ export async function openPopup(
delimSwitch.addEventListener('click', async () => {
delim = delim === '$' ? '$$' : '$'
delimSwitch.innerText = delim === '$' ? 'Inline Math' : 'Display Math'
const contentBeforeCaret = contentBefore + `${delim}${mfe.value}${delim}`
const contentBeforeCaret = mfe.value
? contentBefore + `${delim}${mfe.value}${delim}`
: contentBefore
await logseq.Editor.updateBlock(uuid, contentBeforeCaret + contentAfter)
})
mfe.addEventListener('input', async () => {
await applyAlign()
if (mfe.value.includes('placeholder')) return // not a complete formula
const contentBeforeCaret = contentBefore + `${delim}${mfe.value}${delim}`
const contentBeforeCaret = mfe.value
? contentBefore + `${delim}${mfe.value}${delim}`
: contentBefore
await logseq.Editor.updateBlock(uuid, contentBeforeCaret + contentAfter)
})
mfe.addEventListener('unmount', async () => {
Expand All @@ -93,7 +97,9 @@ export async function openPopup(
if (done) return // avoid insert twice
done = true
logseq.provideUI({ key: 'popup', template: '' }) // close popup
const contentBeforeCaret = contentBefore + `${delim}${mfe.value}${delim}`
const contentBeforeCaret = mfe.value
? contentBefore + `${delim}${mfe.value}${delim}`
: contentBefore
await logseq.Editor.updateBlock(uuid, contentBeforeCaret + contentAfter)
// HACK: `Editor.editBlock` does nothing, focusing using DOM ops
textarea.focus()
Expand Down

0 comments on commit 3bcb491

Please sign in to comment.