From 2254709d4552fb493353db372292b0ac7d138a38 Mon Sep 17 00:00:00 2001 From: Carlos Galdino Date: Wed, 1 May 2024 08:16:26 +0100 Subject: [PATCH] Filter due notes when all are scheduled Ignore notes due in the future. Fixes https://github.com/st3v3nmw/obsidian-spaced-repetition/issues/548 --- docs/changelog.md | 4 ++++ src/main.ts | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index a740e670..9479ea15 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +[Unreleased] + +- Fixed notes selection when all notes are reviewed. [`#548`](https://github.com/st3v3nmw/obsidian-spaced-repetition/issues/548) + #### [1.12.4](https://github.com/st3v3nmw/obsidian-spaced-repetition/compare/1.12.3...1.12.4) - chore: fix package manager issue in CI [`#939`](https://github.com/st3v3nmw/obsidian-spaced-repetition/pull/939) diff --git a/src/main.ts b/src/main.ts index a8c3c278..22c1d3b3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -756,11 +756,13 @@ export default class SRPlugin extends Plugin { this.lastSelectedReviewDeck = deckKey; const deck = this.reviewDecks[deckKey]; - if (deck.dueNotesCount > 0) { + const nowUnix = Date.now(); + const dueNotes = deck.scheduledNotes.filter((note) => note.dueUnix <= nowUnix); + if (dueNotes.length > 0) { const index = this.data.settings.openRandomNote - ? Math.floor(Math.random() * deck.dueNotesCount) + ? Math.floor(Math.random() * dueNotes.length) : 0; - await this.app.workspace.getLeaf().openFile(deck.scheduledNotes[index].note); + await this.app.workspace.getLeaf().openFile(dueNotes[index].note); return; }