mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
This commit is contained in:
parent
71501030c9
commit
2b28b193cb
1 changed files with 66 additions and 0 deletions
|
|
@ -135,6 +135,72 @@ func RemoveFlashcards(deckID string, blockIDs []string) (err error) {
|
||||||
deck := Decks[deckID]
|
deck := Decks[deckID]
|
||||||
deckLock.Unlock()
|
deckLock.Unlock()
|
||||||
|
|
||||||
|
var rootIDs []string
|
||||||
|
blockRoots := map[string]string{}
|
||||||
|
for _, blockID := range blockIDs {
|
||||||
|
bt := treenode.GetBlockTree(blockID)
|
||||||
|
if nil == bt {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
rootIDs = append(rootIDs, bt.RootID)
|
||||||
|
blockRoots[blockID] = bt.RootID
|
||||||
|
}
|
||||||
|
rootIDs = gulu.Str.RemoveDuplicatedElem(rootIDs)
|
||||||
|
|
||||||
|
trees := map[string]*parse.Tree{}
|
||||||
|
for _, blockID := range blockIDs {
|
||||||
|
rootID := blockRoots[blockID]
|
||||||
|
|
||||||
|
tree := trees[rootID]
|
||||||
|
if nil == tree {
|
||||||
|
tree, _ = loadTreeByBlockID(blockID)
|
||||||
|
}
|
||||||
|
if nil == tree {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
trees[rootID] = tree
|
||||||
|
|
||||||
|
node := treenode.GetNodeInTree(tree, blockID)
|
||||||
|
if nil == node {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
oldAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||||
|
|
||||||
|
deckAttrs := node.IALAttr("custom-riff-decks")
|
||||||
|
var deckIDs []string
|
||||||
|
for _, dID := range strings.Split(deckAttrs, ",") {
|
||||||
|
if dID != deckID {
|
||||||
|
deckIDs = append(deckIDs, dID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deckIDs = gulu.Str.RemoveDuplicatedElem(deckIDs)
|
||||||
|
val := strings.Join(deckIDs, ",")
|
||||||
|
val = strings.TrimPrefix(val, ",")
|
||||||
|
val = strings.TrimSuffix(val, ",")
|
||||||
|
if "" == val {
|
||||||
|
node.RemoveIALAttr("custom-riff-decks")
|
||||||
|
} else {
|
||||||
|
node.SetIALAttr("custom-riff-decks", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = indexWriteJSONQueue(tree); nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cache.PutBlockIAL(blockID, parse.IAL2Map(node.KramdownIAL))
|
||||||
|
|
||||||
|
newAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||||
|
doOp := &Operation{Action: "updateAttrs", Data: map[string]interface{}{"old": oldAttrs, "new": newAttrs}, ID: blockID}
|
||||||
|
trans := []*Transaction{{
|
||||||
|
DoOperations: []*Operation{doOp},
|
||||||
|
UndoOperations: []*Operation{},
|
||||||
|
}}
|
||||||
|
pushBroadcastAttrTransactions(trans)
|
||||||
|
}
|
||||||
|
|
||||||
for _, blockID := range blockIDs {
|
for _, blockID := range blockIDs {
|
||||||
deck.RemoveCard(blockID)
|
deck.RemoveCard(blockID)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue