You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I also noticed that the checkpoint facility doesn't seem to work in new Anki as it should (ctrl-z should undo all the added characters in one step). Instead it removes them one by one, up to maximum of 30 (undo queue limit).
Let's look at the function in kanji.py more closely:
def make_cards_from_characters(self, card_type, new_characters, checkpoint=None):
from . import add_note_no_hook
# Just to be sure...
self.recalc_user_cards(card_type)
characters = self.new_characters(card_type, new_characters)
deck_name = card_type.deck_name
model_name = card_type.model_name
deck = aqt.mw.col.decks.byName(deck_name)
if deck is None:
raise InvalidDeckError(card_type)
if checkpoint is not None:
aqt.mw.checkpoint(checkpoint)
deck_id = deck["id"]
model = aqt.mw.col.models.byName(model_name)
for c in characters:
note = anki.notes.Note(aqt.mw.col, model)
note["Character"] = c
self.refresh_note(note)
add_note_no_hook(aqt.mw.col, note, deck_id)
self.recalc_user_cards(card_type)
The mw.checkpoint() in current version doesn't seem to do anything worthwhile, since add_note_no_hook (call to pylib.anki.collection.Collection.add_note) will always reset the undo queue anyway, and so one extra checkpoint is added per new note.
So we should be using col.add_custom_undo_entry() / col.merge_undo_entries() instead of mw.checkpoint()
The CollectionOp wrapping here is needed for GUI to be updated.
However I'm not sure how to apply this to our code since we need to call recalc_user_cards() after adding the notes. How to wait for it to complete?
The text was updated successfully, but these errors were encountered:
I also noticed that the checkpoint facility doesn't seem to work in new Anki as it should (ctrl-z should undo all the added characters in one step). Instead it removes them one by one, up to maximum of 30 (undo queue limit).
Let's look at the function in kanji.py more closely:
The mw.checkpoint() in current version doesn't seem to do anything worthwhile, since add_note_no_hook (call to pylib.anki.collection.Collection.add_note) will always reset the undo queue anyway, and so one extra checkpoint is added per new note.
I've tried really hard to understand the porting to Anki 2.1.45 notes here
In the porting note's there's an example how to use the CollectionOp facility:
So we should be using col.add_custom_undo_entry() / col.merge_undo_entries() instead of mw.checkpoint()
The CollectionOp wrapping here is needed for GUI to be updated.
However I'm not sure how to apply this to our code since we need to call recalc_user_cards() after adding the notes. How to wait for it to complete?
The text was updated successfully, but these errors were encountered: