An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Use dynamic anchor text for created database item documents https://github.com/siyuan-note/siyuan/issues/13641
Daniel50714a0a1ed1
diff --git a/kernel/model/attribute_view_new_item.go b/kernel/model/attribute_view_new_item.goindex 4a301d03be..298b25729b 100644--- a/kernel/model/attribute_view_new_item.go+++ b/kernel/model/attribute_view_new_item.go@@ -233,13 +233,11 @@ func CreateAttributeViewItemDocs(avID, blockID, saveMode string, itemIDs []strinif nil != err {return nil, newItemCreationError(err, cleanupCreatedDocs())}- item.bound = item.original.Clone()- if nil == item.bound {- return nil, newItemCreationError(fmt.Errorf("clone attribute view item [%s] failed", item.itemID), cleanupCreatedDocs())+ icon, _ := getNodeAvBlockText(item.tree.Root, "")+ item.bound, err = newBoundAttributeViewItemValue(item.original, item.docID, icon)+ if nil != err {+ return nil, newItemCreationError(fmt.Errorf("bind attribute view item [%s] failed: %w", item.itemID, err), cleanupCreatedDocs())}- item.bound.IsDetached = false- item.bound.Block.ID = item.docID- item.bound.Block.Icon, _ = getNodeAvBlockText(item.tree.Root, "")ret.ItemIDs = append(ret.ItemIDs, item.itemID)ret.BlockIDs = append(ret.BlockIDs, item.docID)}@@ -289,6 +287,18 @@ func CreateAttributeViewItemDocs(avID, blockID, saveMode string, itemIDs []strinreturn ret, nil}+func newBoundAttributeViewItemValue(original *av.Value, docID, icon string) (*av.Value, error) {+ bound := original.Clone()+ if nil == bound || nil == bound.Block {+ return nil, errors.New("clone attribute view item failed")+ }+ bound.IsDetached = false+ bound.Block.ID = docID+ bound.Block.Content = ""+ bound.Block.Icon = icon+ return bound, nil+}+func lockAttributeViewItemDocs(avID string) func() {lockValue, _ := attributeViewItemDocsLocks.LoadOrStore(avID, &sync.Mutex{})lock := lockValue.(*sync.Mutex)diff --git a/kernel/model/attribute_view_new_item_test.go b/kernel/model/attribute_view_new_item_test.goindex 6287fea44d..7db5cd4c17 100644--- a/kernel/model/attribute_view_new_item_test.go+++ b/kernel/model/attribute_view_new_item_test.go@@ -101,6 +101,25 @@ func TestAttributeViewItemDocumentTemplate(t *testing.T) {}}+func TestNewBoundAttributeViewItemValueUsesDynamicAnchorText(t *testing.T) {+ original := &av.Value{+ Type: av.KeyTypeBlock,+ IsDetached: true,+ Block: &av.ValueBlock{Content: "Detached item"},+ }+ docID := ast.NewNodeID()+ bound, err := newBoundAttributeViewItemValue(original, docID, "1f4c4")+ if nil != err {+ t.Fatalf("create bound attribute view item value failed: %s", err)+ }+ if bound.IsDetached || docID != bound.Block.ID || "" != bound.Block.Content || "1f4c4" != bound.Block.Icon {+ t.Fatalf("the bound item should use dynamic anchor text: %+v", bound)+ }+ if !original.IsDetached || "" != original.Block.ID || "Detached item" != original.Block.Content {+ t.Fatalf("the original detached item should remain unchanged: %+v", original)+ }+}+func TestLockAttributeViewItemDocs(t *testing.T) {avID := ast.NewNodeID()unlock := lockAttributeViewItemDocs(avID)