From 92eeb8d749740ef4d6500dc59968e9310528eb02 Mon Sep 17 00:00:00 2001 From: YuLong Yao Date: Thu, 18 May 2023 17:29:46 +0800 Subject: [PATCH 1/3] Readme: add guiUndo action --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 4785900..19a008b 100644 --- a/README.md +++ b/README.md @@ -1469,6 +1469,32 @@ corresponding to when the API was available for use. ``` +#### `guiUndo` + +* Undo the last action / card; returns `true` if succeeded or `false` otherwise. + +
+ Sample request: + + ```json + { + "action": "guiUndo", + "version": 6 + } + ``` +
+ +
+ Sample result: + + ```json + { + "result": true, + "error": null + } + ``` +
+ #### `guiDeckOverview` * Opens the *Deck Overview* dialog for the deck with the given name; returns `true` if succeeded or `false` otherwise. From 53dba8003b1f48806bff55c06adc155c67627bd9 Mon Sep 17 00:00:00 2001 From: YuLong Yao Date: Thu, 18 May 2023 17:30:14 +0800 Subject: [PATCH 2/3] api: add guiUndo action --- plugin/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugin/__init__.py b/plugin/__init__.py index a30fca0..73f4d81 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -1801,6 +1801,12 @@ class AnkiConnect: return True + @util.api() + def guiUndo(self): + self.window().undo() + return True + + @util.api() def guiDeckOverview(self, name): collection = self.collection() From 5516e4826ce8937bf9a0d776ade93559ba4de9e7 Mon Sep 17 00:00:00 2001 From: YuLong Yao Date: Thu, 18 May 2023 17:30:18 +0800 Subject: [PATCH 3/3] test: add guiUndo action --- tests/test_graphical.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_graphical.py b/tests/test_graphical.py index cabcfea..6311bb4 100755 --- a/tests/test_graphical.py +++ b/tests/test_graphical.py @@ -102,6 +102,19 @@ class TestReviewActions: reviews_after = ac.cardReviews(deck="test_deck", startID=0) assert len(reviews_after) == len(reviews_before) + 1 + def test_guiUndo(self, reviewing_started): + ac.guiShowAnswer() + reviews_before = ac.cardReviews(deck="test_deck", startID=0) + assert ac.guiAnswerCard(ease=4) is True + + reviews_after_answer = ac.cardReviews(deck="test_deck", startID=0) + assert len(reviews_after_answer) == len(reviews_before) + 1 + + assert ac.guiUndo() is True + + reviews_after_undo = ac.cardReviews(deck="test_deck", startID=0) + assert len(reviews_after_undo) == len(reviews_before) + class TestSelectedNotes: def test_with_valid_deck_query(self, setup):