Explorar o código

:art: 改进动态加载判断 Fix https://github.com/siyuan-note/siyuan/issues/7693

Liang Ding %!s(int64=2) %!d(string=hai) anos
pai
achega
b81152515c

+ 1 - 1
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");

+ 1 - 1
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;

+ 1 - 1
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,

+ 2 - 2
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,

+ 21 - 2
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