Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Commit

Permalink
change flush to add_note
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsumoto-ren committed Oct 15, 2021
1 parent 45a4508 commit e6df2b7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"furigana_suffix": " (furigana)",
"skip_numbers": true,
"generate_on_flush": true,
"generate_on_note_add": true,
"skip_words": "人,一,二",
"toolbar": {
"furigana_button": {
Expand Down
2 changes: 1 addition & 1 deletion config.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ If a field called "abc" exists, and another field called "abc
Whether to add furigana to numbers or not.
* `skip_words`.
A comma-separated list of words that should be skipped when adding furigana.
* `generate_on_flush`.
* `generate_on_note_add`.
Automatically add readings to cards created by AnkiConnect with
[Yomichan](https://foosoft.net/projects/yomichan/).
* `toolbar`.
Expand Down
3 changes: 3 additions & 0 deletions helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright: Ren Tatsumoto <tatsu at autistici.org>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html

import re
from typing import Iterator, Tuple

Expand Down
11 changes: 6 additions & 5 deletions reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

from typing import List

from anki import hooks
import anki.collection
from anki.hooks import wrap
from anki.utils import htmlToTextLine

from .helpers import *
Expand Down Expand Up @@ -75,11 +76,11 @@ def on_focus_lost(changed: bool, note: Note, field_idx: int) -> bool:
return True if fill_destination(note, src_field, dst_field) else changed


# Note will flush hook
# Note add hook
##########################################################################

def on_note_will_flush(note: Note) -> None:
if not config.get('generate_on_flush'):
def on_add_note(_col, note: Note, _did) -> None:
if not config.get('generate_on_note_add'):
return

if mw.app.activeWindow() or note.id:
Expand Down Expand Up @@ -126,4 +127,4 @@ def init():
gui_hooks.editor_did_unfocus_field.append(on_focus_lost)

# Generate when AnkiConnect adds a new note
hooks.note_will_flush.append(on_note_will_flush)
anki.collection.Collection.add_note = wrap(anki.collection.Collection.add_note, on_add_note, 'before')

0 comments on commit e6df2b7

Please sign in to comment.