check both queues when popping answered card
If multiple answers are applied in succession, a newly-due learning card may be in front of the next main entry.
This commit is contained in:
parent
9a0f095e55
commit
187944615e
@ -127,24 +127,21 @@ impl CardQueues {
|
|||||||
/// Remove the provided card from the top of the queues and
|
/// Remove the provided card from the top of the queues and
|
||||||
/// adjust the counts. If it was not at the top, return an error.
|
/// adjust the counts. If it was not at the top, return an error.
|
||||||
fn pop_entry(&mut self, id: CardId) -> Result<QueueEntry> {
|
fn pop_entry(&mut self, id: CardId) -> Result<QueueEntry> {
|
||||||
let mut entry = self.iter().next();
|
// This ignores the current cutoff, so may match if the provided
|
||||||
if entry.is_none() && *crate::PYTHON_UNIT_TESTS {
|
// learning card is not yet due. It should not happen in normal
|
||||||
// the existing Python tests answer learning cards
|
// practice, but does happen in the Python unit tests, as they answer
|
||||||
// before they're due; try the first non-due learning
|
// learning cards early.
|
||||||
// card as a backup
|
if self
|
||||||
entry = self.intraday_learning.front().map(Into::into)
|
.intraday_learning
|
||||||
}
|
.front()
|
||||||
if let Some(entry) = entry {
|
.filter(|e| e.id == id)
|
||||||
match entry {
|
.is_some()
|
||||||
QueueEntry::IntradayLearning(e) if e.id == id => {
|
{
|
||||||
self.pop_intraday_learning().map(Into::into)
|
Ok(self.pop_intraday_learning().unwrap().into())
|
||||||
}
|
} else if self.main.front().filter(|e| e.id == id).is_some() {
|
||||||
QueueEntry::Main(e) if e.id == id => self.pop_main().map(Into::into),
|
Ok(self.pop_main().unwrap().into())
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
.ok_or_else(|| AnkiError::invalid_input("not at top of queue"))
|
|
||||||
} else {
|
} else {
|
||||||
Err(AnkiError::invalid_input("queues are empty"))
|
Err(AnkiError::invalid_input("not at top of queue"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,10 +40,10 @@ impl Collection {
|
|||||||
}
|
}
|
||||||
UndoableQueueChange::CardAnswerUndone(update) => {
|
UndoableQueueChange::CardAnswerUndone(update) => {
|
||||||
let queues = self.get_queues()?;
|
let queues = self.get_queues()?;
|
||||||
|
queues.pop_entry(update.entry.card_id())?;
|
||||||
if let Some(learning) = update.learning_requeue {
|
if let Some(learning) = update.learning_requeue {
|
||||||
queues.insert_intraday_learning_card(learning);
|
queues.insert_intraday_learning_card(learning);
|
||||||
}
|
}
|
||||||
queues.pop_entry(update.entry.card_id())?;
|
|
||||||
self.save_undo(UndoableQueueChange::CardAnswered(update));
|
self.save_undo(UndoableQueueChange::CardAnswered(update));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user