mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 21:21:21 +08:00
🎨 Update av
This commit is contained in:
parent
b6f62eb4ea
commit
ad70e42fd6
@ -58,6 +58,7 @@ func filterRows(ret *av.AttributeView) {
|
||||
}
|
||||
}
|
||||
}
|
||||
colIndexes = util.RemoveDuplicatedElem(colIndexes)
|
||||
|
||||
var rows []*av.Row
|
||||
for _, row := range ret.Rows {
|
||||
@ -92,6 +93,7 @@ func sortRows(ret *av.AttributeView) {
|
||||
}
|
||||
}
|
||||
}
|
||||
colIndexes = util.RemoveDuplicatedElem(colIndexes)
|
||||
|
||||
sort.Slice(ret.Rows, func(i, j int) bool {
|
||||
for _, index := range colIndexes {
|
||||
@ -408,12 +410,12 @@ func sortAttributeViewColumn(columnID, previousColumnID, avID string) (err error
|
||||
break
|
||||
}
|
||||
}
|
||||
attrView.Columns = util.InsertElement(attrView.Columns, previousIndex, col)
|
||||
attrView.Columns = util.InsertElem(attrView.Columns, previousIndex, col)
|
||||
|
||||
for _, row := range attrView.Rows {
|
||||
cel := row.Cells[index]
|
||||
row.Cells = append(row.Cells[:index], row.Cells[index+1:]...)
|
||||
row.Cells = util.InsertElement(row.Cells, previousIndex, cel)
|
||||
row.Cells = util.InsertElem(row.Cells, previousIndex, cel)
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
@ -446,7 +448,7 @@ func sortAttributeViewRow(rowID, previousRowID, avID string) (err error) {
|
||||
break
|
||||
}
|
||||
}
|
||||
attrView.Rows = util.InsertElement(attrView.Rows, previousIndex, row)
|
||||
attrView.Rows = util.InsertElem(attrView.Rows, previousIndex, row)
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
|
@ -24,9 +24,21 @@ import (
|
||||
"github.com/88250/lute/html"
|
||||
)
|
||||
|
||||
// InsertElement inserts a new element value at the specified index position.
|
||||
// RemoveDuplicatedElem removes the duplicated elements from the slice.
|
||||
func RemoveDuplicatedElem(slice []int) (ret []int) {
|
||||
allKeys := make(map[int]bool)
|
||||
for _, item := range slice {
|
||||
if _, value := allKeys[item]; !value {
|
||||
allKeys[item] = true
|
||||
ret = append(ret, item)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// InsertElem inserts a new element value at the specified index position.
|
||||
// 0 <= index <= len(a)
|
||||
func InsertElement[T any](ret []T, index int, value T) []T {
|
||||
func InsertElem[T any](ret []T, index int, value T) []T {
|
||||
if len(ret) == index { // nil or empty slice or after last element
|
||||
return append(ret, value)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user