Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Don't recalculate remaining steps, conditionally
Bug report reproduction steps:
Create a new profile so that everything is set to default.
Create a new card.
Click Good.
Open deck options and empty learning steps. Save.
No go back and put 1m 10m as LS.
Go back to the card and it should show 10m on the Good button.

Check if old_steps is empty and if it is just use remaining
steps for the new_remaining steps. Add test.
  • Loading branch information
graves committed Mar 8, 2025
commit f335c1c8fb6701c21ecb67ed3a924847fedfcb8e
36 changes: 34 additions & 2 deletions rslib/src/card/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ impl Card {
/// greater delay, but output will be at least 1.
fn new_remaining_steps(&self, new_steps: &[f32], old_steps: &[f32]) -> Option<u32> {
let remaining = self.remaining_steps();
let new_remaining = old_steps

let new_remaining = if old_steps.len() == 0 {
remaining
} else {
old_steps
.len()
.checked_sub(remaining as usize + 1)
.and_then(|last_index| {
Expand All @@ -249,7 +253,9 @@ impl Card {
// no last delay or last delay is less than all new steps → all steps remain
.unwrap_or(new_steps.len())
// (re)learning card must have at least 1 step remaining
.max(1) as u32;
.max(1) as u32
};

(remaining != new_remaining).then_some(new_remaining)
}

Expand Down Expand Up @@ -493,6 +499,9 @@ mod test {
use crate::tests::open_test_collection_with_learning_card;
use crate::tests::open_test_collection_with_relearning_card;
use crate::tests::DeckAdder;
use crate::prelude::Collection;
use crate::prelude::DeckId;
use crate::prelude::AnkiError;

#[test]
fn should_increase_remaining_learning_steps_if_new_deck_has_more_unpassed_ones() {
Expand All @@ -515,4 +524,27 @@ mod test {
col.set_deck(&[card_id], deck.id).unwrap();
assert_eq!(col.get_first_card().remaining_steps, 2);
}

#[test]
fn should_not_recalculate_remaining_steps_if_there_are_no_old_steps() -> Result<(), AnkiError> {
let mut col = Collection::new();

let nt = col.get_notetype_by_name("Basic")?.unwrap();
let mut note = nt.new_note();
col.add_note(&mut note, DeckId(1))?;

let card_id = col.get_first_card().id;
col.set_deck(&[card_id], DeckId(1))?;

col.set_default_learn_steps(vec![1., 10.]);

let _post_answer = col.answer_good();

col.set_default_learn_steps(vec![]);
col.set_default_learn_steps(vec![1., 10.]);

assert_eq!(col.get_first_card().remaining_steps, 1);

Ok(())
}
}