mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-03 15:28:49 +01:00
♻️ Refactor av data structure
This commit is contained in:
parent
96530382f2
commit
dfa561c62c
2 changed files with 30 additions and 0 deletions
|
|
@ -267,6 +267,10 @@ func (table *Table) GetID() string {
|
|||
}
|
||||
|
||||
func (table *Table) SortRows() {
|
||||
sort.Slice(table.Rows, func(i, j int) bool { return table.Rows[i].ID < table.Rows[j].ID })
|
||||
|
||||
// sort by row ids
|
||||
|
||||
if 1 > len(table.Sorts) {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
|
|
@ -126,6 +127,22 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
|||
}
|
||||
ret.Rows = append(ret.Rows, &tableRow)
|
||||
}
|
||||
|
||||
sortRowIDs := map[string]int{}
|
||||
if 0 < len(view.Table.RowIDs) {
|
||||
for i, rowID := range view.Table.RowIDs {
|
||||
sortRowIDs[rowID] = i
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(ret.Rows, func(i, j int) bool {
|
||||
iv := sortRowIDs[ret.Rows[i].ID]
|
||||
jv := sortRowIDs[ret.Rows[j].ID]
|
||||
if iv == jv {
|
||||
return ret.Rows[i].ID < ret.Rows[j].ID
|
||||
}
|
||||
return iv < jv
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -314,6 +331,8 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
|
|||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
view.Table.RowIDs = append(view.Table.RowIDs, blockID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -337,6 +356,11 @@ func removeAttributeViewBlock(blockID string, operation *Operation) (err error)
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
for _, keyValues := range attrView.KeyValues {
|
||||
for i, values := range keyValues.Values {
|
||||
if values.BlockID == blockID {
|
||||
|
|
@ -346,6 +370,8 @@ func removeAttributeViewBlock(blockID string, operation *Operation) (err error)
|
|||
}
|
||||
}
|
||||
|
||||
view.Table.RowIDs = gulu.Str.RemoveElem(view.Table.RowIDs, blockID)
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue