Skip to content

Commit

Permalink
Merge pull request #88 from migaku-official/fix/add-card
Browse files Browse the repository at this point in the history
fix: look up mids as ints instead of strings
  • Loading branch information
MinmoTech authored Dec 23, 2023
2 parents eb0bb2b + 3eb6b69 commit 2b03e2e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 45 deletions.
28 changes: 12 additions & 16 deletions src/editor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,23 +155,19 @@ def on_migaku_bridge_cmds(self: Editor, cmd: str, _old):

elif cmd.startswith("migakuSelectChange"):
(_, migaku_type, field_name) = cmd.split(":", 2)
migakuFields = get("migakuFields", {})

set(
"migakuFields",
{
**migakuFields,
self.note.mid: {
**(
migakuFields[self.note.mid]
if self.note.mid in migakuFields
else {}
),
field_name: migaku_type,
},
migaku_fields = get("migakuFields", {})
mid_str = str(self.note.mid)
exisiting_mapping = migaku_fields[mid_str] if mid_str in migaku_fields else {}

new_migaku_fields = {
**migaku_fields,
mid_str: {
**exisiting_mapping,
field_name: migaku_type,
},
do_write=True,
)
}

set("migakuFields", new_migaku_fields, do_write=True)
else:
_old(self, cmd)

Expand Down
42 changes: 14 additions & 28 deletions src/editor/current_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,44 +72,30 @@ def add_cards_add_to_history(note):
def get_add_cards_info(defaults=None):
addcards = get_add_cards()

if addcards and defaults:
if addcards:
note = addcards["note"]
tags = note.tags

notetype_id = defaults.notetype_id
notetype = aqt.mw.col.models.get(notetype_id)
notetype_name = notetype["name"]

deck_id = defaults.deck_id
deck = aqt.mw.col.decks.get(deck_id)
deck_name = deck["name"]

fields = get_migaku_fields(notetype)

elif addcards:
note = addcards["note"]
tags = note.tags
notetype = note.note_type()

fields = get_migaku_fields(notetype)
notetype_name = notetype["name"]
notetype_id = notetype["id"]

deck_id = get_current_deck_id()
deck = aqt.mw.col.decks.get(deck_id)
deck_name = deck["name"]
if defaults:
notetype_id = defaults.notetype_id
notetype = aqt.mw.col.models.get(notetype_id)
deck_id = defaults.deck_id
else:
notetype = note.note_type()
notetype_id = notetype["id"]
deck_id = get_current_deck_id()

else:
notetype_id = int(get("migakuNotetypeId", aqt.mw.col.get_config("curModel")))
notetype = aqt.mw.col.models.get(notetype_id)
fields = get_migaku_fields(notetype)
notetype_name = notetype["name"]

deck_id = int(get("migakuDeckId", aqt.mw.col.get_config("curDeck")))
deck = aqt.mw.col.decks.get(deck_id)
deck_name = deck["name"]
tags = []

deck = aqt.mw.col.decks.get(deck_id)
deck_name = deck["name"]
notetype_name = notetype["name"]
fields = get_migaku_fields(notetype)

return {
"fields": fields,
"notetype": notetype,
Expand Down
3 changes: 2 additions & 1 deletion src/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ function MigakuEditor() { }
* @param {string} remove_icon_path
* @param {string} img_filter
*/
MigakuEditor.initButtons = function (add_icon_path, remove_icon_path, img_filter) {
MigakuEditor.initButtons = async function (add_icon_path, remove_icon_path, img_filter) {
await new Promise((resolve) => setTimeout(resolve, 400))
document.querySelector('#migaku_btn_syntax_generate img').src = add_icon_path;
document.querySelector('#migaku_btn_syntax_generate img').style.filter = img_filter;
document.querySelector('#migaku_btn_syntax_remove img').src = remove_icon_path;
Expand Down

0 comments on commit 2b03e2e

Please sign in to comment.