From 77f15e14edf434716ad7c878ec97a64b03eb93de Mon Sep 17 00:00:00 2001 From: Carlos Galdino Date: Mon, 22 Jul 2024 06:02:11 +0100 Subject: [PATCH] Filter due notes when all are scheduled (#947) 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 fac52371..412a8379 100644 --- a/src/main.ts +++ b/src/main.ts @@ -761,11 +761,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; }