瀏覽代碼

Merge remote-tracking branch 'origin/dev' into dev

Vanessa 1 年之前
父節點
當前提交
d0bac97bd5
共有 6 個文件被更改,包括 40 次插入30 次删除
  1. 5 0
      kernel/conf/editor.go
  2. 27 2
      kernel/model/attribute_view.go
  3. 1 1
      kernel/model/blockinfo.go
  4. 4 4
      kernel/model/conf.go
  5. 2 1
      kernel/model/file.go
  6. 1 22
      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,

+ 27 - 2
kernel/model/attribute_view.go

@@ -2943,12 +2943,12 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
 			// 将游离行绑定到新建的块上
 			bindBlockAv(tx, avID, rowID)
 		}
-	} else {                    // 之前绑定了块
+	} else { // 之前绑定了块
 		if isUpdatingBlockKey { // 正在更新主键
 			if val.IsDetached { // 现在是游离行
 				// 将绑定的块从属性视图中移除
 				unbindBlockAv(tx, avID, rowID)
-			} else {                                // 现在绑定了块
+			} else { // 现在绑定了块
 				if oldBoundBlockID != val.BlockID { // 之前绑定的块和现在绑定的块不一样
 					// 换绑块
 					unbindBlockAv(tx, avID, oldBoundBlockID)
@@ -3251,6 +3251,7 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
 		}
 	}
 
+	// 如果存在选项对应的值,需要更新值中的选项
 	for _, keyValues := range attrView.KeyValues {
 		if keyValues.Key.ID != operation.ID {
 			continue
@@ -3272,6 +3273,30 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
 		break
 	}
 
+	// 如果存在选项对应的过滤器,需要更新过滤器中设置的选项值
+	// Database select field filters follow option editing changes https://github.com/siyuan-note/siyuan/issues/10881
+	for _, view := range attrView.Views {
+		switch view.LayoutType {
+		case av.LayoutTypeTable:
+			table := view.Table
+			for _, filter := range table.Filters {
+				if filter.Column != key.ID {
+					continue
+				}
+
+				if nil != filter.Value && (av.KeyTypeSelect == filter.Value.Type || av.KeyTypeMSelect == filter.Value.Type) {
+					for i, opt := range filter.Value.MSelect {
+						if oldName == opt.Content {
+							filter.Value.MSelect[i].Content = newName
+							filter.Value.MSelect[i].Color = newColor
+							break
+						}
+					}
+				}
+			}
+		}
+	}
+
 	err = av.SaveAttributeView(attrView)
 	return
 }

+ 1 - 1
kernel/model/blockinfo.go

@@ -365,7 +365,7 @@ func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string) (ret []*BlockPa
 		if ast.NodeDocument == parent.Type {
 			name = box.Name + hPath
 		} else if ast.NodeAttributeView == parent.Type {
-			name = treenode.GetAttributeViewName(parent.AttributeViewID)
+			name, _ = av.GetAttributeViewName(parent.AttributeViewID)
 		} else {
 			if "" == name {
 				if ast.NodeListItem == parent.Type {

+ 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 - 22
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
 		}
 
@@ -546,27 +546,6 @@ func IsChartCodeBlockCode(code *ast.Node) bool {
 	return render.NoHighlight(language)
 }
 
-func GetAttributeViewName(avID string) (name string) {
-	if "" == avID {
-		return
-	}
-
-	attrView, err := av.ParseAttributeView(avID)
-	if nil != err {
-		logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
-		return
-	}
-
-	buf := bytes.Buffer{}
-	for _, v := range attrView.Views {
-		buf.WriteString(v.Name)
-		buf.WriteByte(' ')
-	}
-
-	name = strings.TrimSpace(buf.String())
-	return
-}
-
 func getAttributeViewContent(avID string) (content string) {
 	if "" == avID {
 		return