From 552dde57cde2e7b08c7e6fd3f97cd459fd0631e5 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 14 Sep 2024 17:53:46 +0800 Subject: [PATCH] :technologist: Improve kernel API appendAttributeViewDetachedBlocksWithValues https://github.com/siyuan-note/siyuan/issues/12475 --- kernel/model/attribute_view.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 524ddc6c6..36ce476ce 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -75,6 +75,23 @@ func AppendAttributeViewDetachedBlocksWithValues(avID string, blocksValues [][]* v.UpdatedAt = now keyValues.Values = append(keyValues.Values, v) + + if av.KeyTypeSelect == v.Type || av.KeyTypeMSelect == v.Type { + // 保存选项 https://github.com/siyuan-note/siyuan/issues/12475 + key, _ := attrView.GetKey(v.KeyID) + if nil != key && 0 < len(v.MSelect) { + for _, valOpt := range v.MSelect { + if opt := key.GetOption(valOpt.Content); nil == opt { + // 不存在的选项新建保存 + opt = &av.SelectOption{Name: valOpt.Content, Color: valOpt.Color} + key.Options = append(key.Options, opt) + } else { + // 已经存在的选项颜色需要保持不变 + valOpt.Color = opt.Color + } + } + } + } } }