eyeinsky / org-anki

Sync org notes to Anki via AnkiConnect
BSD 3-Clause "New" or "Revised" License
176 stars 28 forks source link

Feature: Seamless Card Movement Between Anki Decks Based On Heading's Location #94

Open Logravia opened 6 months ago

Logravia commented 6 months ago

Let's say I have two Anki decks and their respective .org files.

It'd be a nice feature that if I moved a heading from foo.org to bar.org and called org-anki-sync-all the respective card would move from the foo Anki deck to the bar Anki deck.

Action: When a user moves a heading from one .org file to another. Trigger: Upon executing org-anki-sync-all ... Outcome: The associated Anki card switches decks to match the updated .org file organization.

whatacold commented 5 months ago

I'm afraid that there is no way for org-anki to be aware of the movement of notes in this case.

It's possible to glue these 3 operations:

  1. delete from the old deck
  2. refile or move the subtree to a new org file
  3. sync the new org node

But I'm afraid it's not reliable to do it as these operations should be done in a transaction, as like in DB SQL.

eyeinsky commented 5 months ago

So I remembered that I did something special for tags as well: it used to be that AnkiConnect didn't have an API endpoint to update note fields and tags at the same time (there is now), so what I did was got all the old tags for all existing notes, then diffed the current tags (in org-mode) versus the old tags (from Anki), and then added and removed tags as necessary.

Though for tags, it seems that it's not needed anymore, then for decks one could do a similar workaround. I will say though doing this is a major pain :p because (as opposed to Haskell) with elisp there are no static types to help me out keeping the types correct while I develop.

It also seems that the AnkiConnect repo has moved away from github, and apparently it's not currently possible to create issues there asking/suggesting to add "deck update" functionality to the updateNote endpoint. I'll write to the maintainer there to see what he says.