mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964
This commit is contained in:
parent
396450a2ec
commit
7906e8f516
1 changed files with 16 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue