Pārlūkot izejas kodu

:art: Improve doc dynamic loading https://github.com/siyuan-note/siyuan/issues/10851

Daniel 1 gadu atpakaļ
vecāks
revīzija
9c61d2a36f
4 mainītis faili ar 12 papildinājumiem un 6 dzēšanām
  1. 5 0
      kernel/conf/editor.go
  2. 4 4
      kernel/model/conf.go
  3. 2 1
      kernel/model/file.go
  4. 1 1
      kernel/treenode/node.go

+ 5 - 0
kernel/conf/editor.go

@@ -50,6 +50,11 @@ type Editor struct {
 	BackmentionExpandCount          int      `json:"backmentionExpandCount"`          // 反链提及默认展开数量
 }
 
+const (
+	MinDynamicLoadBlocks = 48
+	MaxDynamicLoadBlocks = 1024
+)
+
 func NewEditor() *Editor {
 	return &Editor{
 		FontSize:                        16,

+ 4 - 4
kernel/model/conf.go

@@ -242,11 +242,11 @@ func InitConf() {
 	if 1 > Conf.Editor.HistoryRetentionDays {
 		Conf.Editor.HistoryRetentionDays = 30
 	}
-	if 48 > Conf.Editor.DynamicLoadBlocks {
-		Conf.Editor.DynamicLoadBlocks = 48
+	if conf.MinDynamicLoadBlocks > Conf.Editor.DynamicLoadBlocks {
+		Conf.Editor.DynamicLoadBlocks = conf.MinDynamicLoadBlocks
 	}
-	if 1024 < Conf.Editor.DynamicLoadBlocks {
-		Conf.Editor.DynamicLoadBlocks = 1024
+	if conf.MaxDynamicLoadBlocks < Conf.Editor.DynamicLoadBlocks {
+		Conf.Editor.DynamicLoadBlocks = conf.MaxDynamicLoadBlocks
 	}
 	if 0 > Conf.Editor.BacklinkExpandCount {
 		Conf.Editor.BacklinkExpandCount = 0

+ 2 - 1
kernel/model/file.go

@@ -42,6 +42,7 @@ import (
 	"github.com/siyuan-note/riff"
 	"github.com/siyuan-note/siyuan/kernel/av"
 	"github.com/siyuan-note/siyuan/kernel/cache"
+	"github.com/siyuan-note/siyuan/kernel/conf"
 	"github.com/siyuan-note/siyuan/kernel/filesys"
 	"github.com/siyuan-note/siyuan/kernel/search"
 	"github.com/siyuan-note/siyuan/kernel/sql"
@@ -665,7 +666,7 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s
 			childCount += treenode.CountBlockNodes(n)
 		}
 
-		if childCount > Conf.Editor.DynamicLoadBlocks {
+		if childCount > Conf.Editor.DynamicLoadBlocks && blockCount > conf.MinDynamicLoadBlocks {
 			scroll = true
 			return ast.WalkStop
 		}

+ 1 - 1
kernel/treenode/node.go

@@ -342,7 +342,7 @@ func FirstLeafBlock(node *ast.Node) (ret *ast.Node) {
 
 func CountBlockNodes(node *ast.Node) (ret int) {
 	ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
-		if !entering || !n.IsBlock() || ast.NodeList == n.Type || ast.NodeBlockquote == n.Type || ast.NodeSuperBlock == n.Type {
+		if !entering || !n.IsBlock() || ast.NodeList == n.Type || ast.NodeListItem == n.Type || ast.NodeBlockquote == n.Type || ast.NodeSuperBlock == n.Type {
 			return ast.WalkContinue
 		}