🎨 Update av

This commit is contained in:
Daniel 2023-08-02 00:02:30 +08:00
parent 1e8b5df293
commit 683e9a04ed
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 24 additions and 18 deletions

View file

@ -475,16 +475,14 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
}
func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr) {
for _, id := range operation.SrcIDs {
var avErr error
if avErr = removeAttributeViewBlock(id, operation); nil != avErr {
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID}
}
err := removeAttributeViewBlock(operation)
if nil != err {
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID}
}
return
}
func removeAttributeViewBlock(blockID string, operation *Operation) (err error) {
func removeAttributeViewBlock(operation *Operation) (err error) {
attrView, err := av.ParseAttributeView(operation.AvID)
if nil != err {
return
@ -496,15 +494,18 @@ func removeAttributeViewBlock(blockID string, operation *Operation) (err error)
}
for _, keyValues := range attrView.KeyValues {
tmp := keyValues.Values[:0]
for i, values := range keyValues.Values {
if values.BlockID == blockID {
keyValues.Values = append(keyValues.Values[:i], keyValues.Values[i+1:]...)
break
if !gulu.Str.Contains(values.BlockID, operation.SrcIDs) {
tmp = append(tmp, keyValues.Values[i])
}
}
keyValues.Values = tmp
}
view.Table.RowIDs = gulu.Str.RemoveElem(view.Table.RowIDs, blockID)
for _, blockID := range operation.SrcIDs {
view.Table.RowIDs = gulu.Str.RemoveElem(view.Table.RowIDs, blockID)
}
err = av.SaveAttributeView(attrView)
return

View file

@ -24,16 +24,21 @@ import (
"github.com/88250/lute/html"
)
// InsertElem inserts a new element value at the specified index position.
// 0 <= index <= len(a)
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)
// InsertElem inserts value at index into a.
// 0 <= index <= len(s)
func InsertElem[T any](s []T, index int, value T) []T {
if len(s) == index { // nil or empty slice or after last element
return append(s, value)
}
ret = append(ret[:index+1], ret[index:]...) // index < len(a)
ret[index] = value
return ret
s = append(s[:index+1], s[index:]...) // index < len(s)
s[index] = value
return s
}
// RemoveElem removes the element at index i from s.
func RemoveElem[T any](s []T, index int) []T {
return append(s[:index], s[index+1:]...)
}
func EscapeHTML(s string) string {