From 57d2cd14f02b054f374da8f5cc953a1d4c4ecb90 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 27 Mar 2024 20:11:04 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/10716 --- app/src/protyle/scroll/index.ts | 5 ++++- app/src/protyle/util/onGet.ts | 13 ++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/protyle/scroll/index.ts b/app/src/protyle/scroll/index.ts index 25a01e9ed..8c1d9487b 100644 --- a/app/src/protyle/scroll/index.ts +++ b/app/src/protyle/scroll/index.ts @@ -78,7 +78,7 @@ export class Scroll { }); } - public updateIndex(protyle: IProtyle, id: string) { + public updateIndex(protyle: IProtyle, id: string, cb?:(index: number) => void) { fetchPost("/api/block/getBlockIndex", {id}, (response) => { if (!response.data) { return; @@ -86,6 +86,9 @@ export class Scroll { const inputElement = protyle.scroll.element.querySelector(".b3-slider") as HTMLInputElement; inputElement.value = response.data; protyle.scroll.element.setAttribute("aria-label", `Blocks ${response.data}/${protyle.block.blockCount}`); + if (cb) { + cb(response.data); + } }); } diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts index 0a789f426..f73ed6757 100644 --- a/app/src/protyle/util/onGet.ts +++ b/app/src/protyle/util/onGet.ts @@ -254,11 +254,14 @@ const setHTML = (options: { } if (options.scrollAttr && !protyle.scroll.element.classList.contains("fn__none") && !protyle.element.classList.contains("fn__none")) { // 使用动态滚动条定位到最后一个块,重启后无法触发滚动事件,需要再次更新 index - protyle.scroll.updateIndex(protyle, options.scrollAttr.startId); - // https://github.com/siyuan-note/siyuan/issues/8224 - if (protyle.contentElement.scrollHeight <= protyle.contentElement.clientHeight) { - showMessage(window.siyuan.languages.scrollGetMore); - } + protyle.scroll.updateIndex(protyle, options.scrollAttr.startId, (index) => { + // https://github.com/siyuan-note/siyuan/issues/8224 + // https://github.com/siyuan-note/siyuan/issues/10716 + if (index > 1 && protyle.block.blockCount > 1 && protyle.contentElement.scrollHeight <= protyle.contentElement.clientHeight) { + showMessage(window.siyuan.languages.scrollGetMore); + } + }); + } protyle.app.plugins.forEach(item => { item.eventBus.emit("loaded-protyle", protyle); // 准备废弃