diff --git a/package.json b/package.json index 7b76ffb..64a84c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "logseq-plugin-tocgen", - "version": "2.10.4", + "version": "2.10.5", "main": "dist/index.html", "logseq": { "id": "_sethyuan-logseq-tocgen", diff --git a/src/index.jsx b/src/index.jsx index d4070f4..afb0b67 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -335,13 +335,14 @@ async function main() { routeOff = logseq.App.onRouteChanged( async ({ template, parameters: { query } }) => { if (lastPageUUID) { - const last = lastScrollTop - if (last > 0) { + if (lastScrollTop > 0) { await logseq.Editor.upsertBlockProperty( lastPageUUID, "scroll-top", - last, + lastScrollTop, ) + } else { + await logseq.Editor.removeBlockProperty(lastPageUUID, "scroll-top") } } @@ -363,11 +364,9 @@ async function main() { if (currPage == null) return lastPageUUID = currPage.uuid - if (currPage.properties?.scrollTop != null) { - setTimeout(() => { - gotoOffset(mainContentContainer, currPage.properties.scrollTop) - }, 100) - } + setTimeout(() => { + gotoOffset(mainContentContainer, currPage.properties?.scrollTop ?? 0) + }, 100) } }, )