Skip to content

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

:art: Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964

Daniel7906e8f516eb
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 9406315e8c..56bf2f7a83 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -1569,12 +1569,14 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
type GroupState struct {
Folded bool
Hidden int
+ Sort int
}
groupStates := map[string]*GroupState{}
- for _, groupView := range view.Groups {
+ for i, groupView := range view.Groups {
groupStates[groupView.Name] = &GroupState{
Folded: groupView.GroupFolded,
Hidden: groupView.GroupHidden,
+ Sort: i,
}
}
@@ -1730,7 +1732,7 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
view.GroupUpdated = time.Now().UnixMilli()
- // 则恢复分组视图状态
+ // 恢复分组视图状态
for _, groupView := range view.Groups {
if state, ok := groupStates[groupView.Name]; ok {
groupView.GroupFolded = state.Folded
@@ -1738,6 +1740,18 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
}
}
+ // 恢复分组视图的顺序
+ if len(groupStates) > 0 {
+ sort.SliceStable(view.Groups, func(i, j int) bool {
+ if stateI, ok := groupStates[view.Groups[i].Name]; ok {
+ if stateJ, ok := groupStates[view.Groups[j].Name]; ok {
+ return stateI.Sort < stateJ.Sort
+ }
+ }
+ return false
+ })
+ }
+
if av.GroupOrderMan != view.Group.Order {
sort.SliceStable(view.Groups, func(i, j int) bool {
iName, jName := view.Groups[i].Name, view.Groups[j].Name