From 740761fcc871ce8be72326d4e5d34a15f1348259 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 21 Feb 2023 10:15:57 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E5=9C=A8=20All=20?= =?UTF-8?q?=E5=8D=A1=E5=8C=85=E4=B8=AD=E7=A7=BB=E9=99=A4=E9=97=AA=E5=8D=A1?= =?UTF-8?q?=20Fix=20https://github.com/siyuan-note/siyuan/issues/7425?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/flashcard.go | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index 61d6ba695..4d55ccd6c 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -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()