diff --git a/app/src/protyle/scroll/index.ts b/app/src/protyle/scroll/index.ts index c6b5c1444..4b0788c7b 100644 --- a/app/src/protyle/scroll/index.ts +++ b/app/src/protyle/scroll/index.ts @@ -82,7 +82,7 @@ export class Scroll { if (protyle.block.showAll) { this.element.classList.add("fn__none"); } else { - if (protyle.block.childBlockCount > window.siyuan.config.editor.dynamicLoadBlocks) { + if (protyle.block.scroll) { this.element.classList.remove("fn__none"); } else { this.element.classList.add("fn__none"); diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts index 683617de9..20da2f73f 100644 --- a/app/src/protyle/util/onGet.ts +++ b/app/src/protyle/util/onGet.ts @@ -72,7 +72,7 @@ export const onGet = (data: IWebSocketData, protyle: IProtyle, action: string[] protyle.block.showAll = false; protyle.block.mode = data.data.mode; protyle.block.blockCount = data.data.blockCount; - protyle.block.childBlockCount = data.data.childBlockCount; + protyle.block.scroll = data.data.scroll; protyle.block.action = action; if (!action.includes(Constants.CB_GET_UNCHANGEID)) { protyle.block.id = data.data.id; diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.ts index 1fc19c451..0c1dd906d 100644 --- a/app/src/types/protyle.d.ts +++ b/app/src/types/protyle.d.ts @@ -409,7 +409,7 @@ interface IProtyle { id: string, block: { id?: string, - childBlockCount?: number, + scroll?: boolean parentID?: string, parent2ID?: string, rootID?: string, diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index 45f9cfd2c..d35d9462e 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -690,7 +690,7 @@ func getDoc(c *gin.Context) { isBacklink = isBacklinkArg.(bool) } - blockCount, childBlockCount, content, parentID, parent2ID, rootID, typ, eof, boxID, docPath, isBacklinkExpand, err := model.GetDoc(startID, endID, id, index, keyword, mode, size, isBacklink) + blockCount, content, parentID, parent2ID, rootID, typ, eof, scroll, boxID, docPath, isBacklinkExpand, err := model.GetDoc(startID, endID, id, index, keyword, mode, size, isBacklink) if errors.Is(err, filelock.ErrUnableAccessFile) { ret.Code = 2 ret.Data = id @@ -719,8 +719,8 @@ func getDoc(c *gin.Context) { "type": typ, "content": content, "blockCount": blockCount, - "childBlockCount": childBlockCount, "eof": eof, + "scroll": scroll, "box": boxID, "path": docPath, "isSyncing": isSyncing, diff --git a/kernel/model/file.go b/kernel/model/file.go index 5833b3c2c..301e1bbc8 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -414,7 +414,7 @@ func StatTree(id string) (ret *util.BlockStatResult) { } } -func GetDoc(startID, endID, id string, index int, keyword string, mode int, size int, isBacklink bool) (blockCount, childBlockCount int, dom, parentID, parent2ID, rootID, typ string, eof bool, boxID, docPath string, isBacklinkExpand bool, err error) { +func GetDoc(startID, endID, id string, index int, keyword string, mode int, size int, isBacklink bool) (blockCount int, dom, parentID, parent2ID, rootID, typ string, eof, scroll bool, boxID, docPath string, isBacklinkExpand bool, err error) { //os.MkdirAll("pprof", 0755) //cpuProfile, _ := os.Create("pprof/GetDoc") //pprof.StartCPUProfile(cpuProfile) @@ -540,7 +540,6 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, size } blockCount = tree.DocBlockCount() - childBlockCount = treenode.CountBlockNodes(tree.Root) if ast.NodeDocument == node.Type { parentID = node.ID parent2ID = parentID @@ -561,6 +560,26 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, size typ = node.Type.String() } + // 判断是否需要显示动态加载滚动条 https://github.com/siyuan-note/siyuan/issues/7693 + childCount := 0 + ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { + if !entering { + return ast.WalkContinue + } + + if 1 > childCount { + childCount = 1 + } else { + childCount += treenode.CountBlockNodes(n) + } + + if childCount > Conf.Editor.DynamicLoadBlocks { + scroll = true + return ast.WalkStop + } + return ast.WalkContinue + }) + var nodes []*ast.Node if isBacklink { // 引用计数浮窗请求,需要按照反链逻辑组装 https://github.com/siyuan-note/siyuan/issues/6853