Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Allow tab items as parent blocks https://github.com/siyuan-note/siyuan/issues/19428

Daniel06aa22e174b6
diff --git a/kernel/model/block.go b/kernel/model/block.go
index a47944174c..c4cdf39f3a 100644
--- a/kernel/model/block.go
+++ b/kernel/model/block.go
@@ -86,7 +86,7 @@ type RiffCard struct {
func (block *Block) IsContainerBlock() bool {
switch block.Type {
- case "NodeDocument", "NodeBlockquote", "NodeList", "NodeListItem", "NodeSuperBlock", "NodeCallout":
+ case "NodeDocument", "NodeBlockquote", "NodeList", "NodeListItem", "NodeSuperBlock", "NodeCallout", "NodeTabs", "NodeTabItem":
return true
}
return false
diff --git a/kernel/model/block_container_test.go b/kernel/model/block_container_test.go
new file mode 100644
index 0000000000..2ca80e3e9e
--- /dev/null
+++ b/kernel/model/block_container_test.go
@@ -0,0 +1,18 @@
+package model
+
+import "testing"
+
+func TestBlockIsContainerBlock(t *testing.T) {
+ for _, typ := range []string{"NodeDocument", "NodeBlockquote", "NodeList", "NodeListItem", "NodeSuperBlock", "NodeCallout", "NodeTabs", "NodeTabItem"} {
+ block := &Block{Type: typ}
+ if !block.IsContainerBlock() {
+ t.Errorf("expected %q to be a container block", typ)
+ }
+ }
+ for _, typ := range []string{"NodeHeading", "NodeParagraph", "NodeCodeBlock", "", "unknown"} {
+ block := &Block{Type: typ}
+ if block.IsContainerBlock() {
+ t.Errorf("expected %q to be a leaf block", typ)
+ }
+ }
+}
diff --git a/kernel/treenode/blocktree.go b/kernel/treenode/blocktree.go
index 80fbb93449..d43d2eb495 100644
--- a/kernel/treenode/blocktree.go
+++ b/kernel/treenode/blocktree.go
@@ -498,7 +498,7 @@ func GetBlockTree(id string) (ret *BlockTree) {
// 入参 abbrType 对应 BlockTree.Type(如 "d"/"h"/"p"),由 TypeAbbr 写入。
func IsContainerType(abbrType string) bool {
switch abbrType {
- case "d", "b", "l", "i", "s", "callout":
+ case "d", "b", "l", "i", "s", "callout", "tab":
return true
}
return false
diff --git a/kernel/treenode/container_type_test.go b/kernel/treenode/container_type_test.go
new file mode 100644
index 0000000000..f287330d12
--- /dev/null
+++ b/kernel/treenode/container_type_test.go
@@ -0,0 +1,16 @@
+package treenode
+
+import "testing"
+
+func TestIsContainerType(t *testing.T) {
+ for _, typ := range []string{"d", "b", "l", "i", "s", "callout", "tab"} {
+ if !IsContainerType(typ) {
+ t.Errorf("expected %q to accept child blocks", typ)
+ }
+ }
+ for _, typ := range []string{"tabs", "h", "p", "c", "", "unknown"} {
+ if IsContainerType(typ) {
+ t.Errorf("expected %q to reject direct child writes", typ)
+ }
+ }
+}