🎨 支持在 All 卡包中移除闪卡 Fix https://github.com/siyuan-note/siyuan/issues/7425
This commit is contained in:
parent
bb0776bd38
commit
740761fcc8
1 changed files with 26 additions and 12 deletions
|
@ -379,9 +379,11 @@ func RemoveFlashcards(deckID string, blockIDs []string) (err error) {
|
|||
|
||||
deckAttrs := node.IALAttr("custom-riff-decks")
|
||||
var deckIDs []string
|
||||
for _, dID := range strings.Split(deckAttrs, ",") {
|
||||
if dID != deckID && gulu.Str.Contains(dID, availableDeckIDs) {
|
||||
deckIDs = append(deckIDs, dID)
|
||||
if "" != deckID {
|
||||
for _, dID := range strings.Split(deckAttrs, ",") {
|
||||
if dID != deckID && gulu.Str.Contains(dID, availableDeckIDs) {
|
||||
deckIDs = append(deckIDs, dID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -410,20 +412,32 @@ func RemoveFlashcards(deckID string, blockIDs []string) (err error) {
|
|||
pushBroadcastAttrTransactions(trans)
|
||||
}
|
||||
|
||||
deck := Decks[deckID]
|
||||
if nil != deck {
|
||||
for _, blockID := range blockIDs {
|
||||
deck.RemoveCard(blockID)
|
||||
}
|
||||
err = deck.Save()
|
||||
if nil != err {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", deckID, err)
|
||||
return
|
||||
if "" == deckID { // 支持在 All 卡包中移除闪卡 https://github.com/siyuan-note/siyuan/issues/7425
|
||||
for _, deck := range Decks {
|
||||
removeFlashcard(blockIDs, deck)
|
||||
}
|
||||
} else {
|
||||
removeFlashcard(blockIDs, Decks[deckID])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func removeFlashcard(blockIDs []string, deck *riff.Deck) {
|
||||
if nil == deck {
|
||||
logging.LogErrorf("deck is nil")
|
||||
return
|
||||
}
|
||||
|
||||
for _, blockID := range blockIDs {
|
||||
deck.RemoveCard(blockID)
|
||||
}
|
||||
|
||||
err := deck.Save()
|
||||
if nil != err {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", deck.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func AddFlashcards(deckID string, blockIDs []string) (err error) {
|
||||
deckLock.Lock()
|
||||
defer deckLock.Unlock()
|
||||
|
|
Loading…
Add table
Reference in a new issue