mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🎨 Update av
This commit is contained in:
parent
1e8b5df293
commit
683e9a04ed
2 changed files with 24 additions and 18 deletions
|
|
@ -475,16 +475,14 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr) {
|
func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr) {
|
||||||
for _, id := range operation.SrcIDs {
|
err := removeAttributeViewBlock(operation)
|
||||||
var avErr error
|
if nil != err {
|
||||||
if avErr = removeAttributeViewBlock(id, operation); nil != avErr {
|
|
||||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID}
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeAttributeViewBlock(blockID string, operation *Operation) (err error) {
|
func removeAttributeViewBlock(operation *Operation) (err error) {
|
||||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
|
|
@ -496,15 +494,18 @@ func removeAttributeViewBlock(blockID string, operation *Operation) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, keyValues := range attrView.KeyValues {
|
for _, keyValues := range attrView.KeyValues {
|
||||||
|
tmp := keyValues.Values[:0]
|
||||||
for i, values := range keyValues.Values {
|
for i, values := range keyValues.Values {
|
||||||
if values.BlockID == blockID {
|
if !gulu.Str.Contains(values.BlockID, operation.SrcIDs) {
|
||||||
keyValues.Values = append(keyValues.Values[:i], keyValues.Values[i+1:]...)
|
tmp = append(tmp, keyValues.Values[i])
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
keyValues.Values = tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, blockID := range operation.SrcIDs {
|
||||||
view.Table.RowIDs = gulu.Str.RemoveElem(view.Table.RowIDs, blockID)
|
view.Table.RowIDs = gulu.Str.RemoveElem(view.Table.RowIDs, blockID)
|
||||||
|
}
|
||||||
|
|
||||||
err = av.SaveAttributeView(attrView)
|
err = av.SaveAttributeView(attrView)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -24,16 +24,21 @@ import (
|
||||||
"github.com/88250/lute/html"
|
"github.com/88250/lute/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InsertElem inserts a new element value at the specified index position.
|
// InsertElem inserts value at index into a.
|
||||||
// 0 <= index <= len(a)
|
// 0 <= index <= len(s)
|
||||||
func InsertElem[T any](ret []T, index int, value T) []T {
|
func InsertElem[T any](s []T, index int, value T) []T {
|
||||||
if len(ret) == index { // nil or empty slice or after last element
|
if len(s) == index { // nil or empty slice or after last element
|
||||||
return append(ret, value)
|
return append(s, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = append(ret[:index+1], ret[index:]...) // index < len(a)
|
s = append(s[:index+1], s[index:]...) // index < len(s)
|
||||||
ret[index] = value
|
s[index] = value
|
||||||
return ret
|
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 {
|
func EscapeHTML(s string) string {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue