mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
Fix panic when clearing today limits on the day collection was made (#3877)
* fix panic on clearing today limits on the day collection was made * avoid possible overflow * clear future today limits
This commit is contained in:
parent
a766f511dd
commit
886c5795d4
1 changed files with 10 additions and 4 deletions
|
@ -411,10 +411,16 @@ fn update_deck_limits(deck: &mut NormalDeck, limits: &Limits, today: u32) {
|
|||
fn update_day_limit(day_limit: &mut Option<DayLimit>, new_limit: Option<u32>, today: u32) {
|
||||
if let Some(limit) = new_limit {
|
||||
day_limit.replace(DayLimit { limit, today });
|
||||
} else if let Some(limit) = day_limit {
|
||||
// instead of setting to None, only make sure today is in the past,
|
||||
// thus preserving last used value
|
||||
limit.today = limit.today.min(today - 1);
|
||||
} else {
|
||||
// if the collection was created today, the
|
||||
// "preserve last value" hack below won't work
|
||||
// clear "future" limits as well (from imports)
|
||||
day_limit.take_if(|limit| limit.today == 0 || limit.today > today);
|
||||
if let Some(limit) = day_limit {
|
||||
// instead of setting to None, only make sure today is in the past,
|
||||
// thus preserving last used value
|
||||
limit.today = limit.today.min(today.saturating_sub(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue