diff --git a/cloze_overlapper/config.py b/cloze_overlapper/config.py index 181713b..3e472ef 100644 --- a/cloze_overlapper/config.py +++ b/cloze_overlapper/config.py @@ -205,11 +205,11 @@ def setupValues(self, config): def onAccept(self): modified = False + config = loadConfig() try: - modified = self.renameFields() + modified = self.renameFields(config) except AnkiError: # rejected full sync warning return - config = mw.col.conf['olcloze'] before = self.f.sb_before.value() after = self.f.sb_after.value() prompt = self.f.sb_cloze.value() @@ -232,7 +232,7 @@ def onRestore(self): def onReject(self): self.close() - def renameFields(self): + def renameFields(self, config): """Check for modified names and rename fields accordingly""" modified = False model = mw.col.models.byName(OLC_MODEL) @@ -241,7 +241,7 @@ def renameFields(self): if not fnedit.isModified(): continue name = fnedit.text() - oldname = mw.col.conf['olcloze']['flds'][key] + oldname = config['flds'][key] if name is None or not name.strip() or name == oldname: continue idx = mw.col.models.fieldNames(model).index(oldname) @@ -250,6 +250,6 @@ def renameFields(self): # rename note type fields mw.col.models.renameField(model, fld, name) # update olcloze field-id <-> field-name assignment - mw.col.conf['olcloze']['flds'][key] = name + config['flds'][key] = name modified = True return modified diff --git a/cloze_overlapper/main.py b/cloze_overlapper/main.py index 52c2db1..2993110 100644 --- a/cloze_overlapper/main.py +++ b/cloze_overlapper/main.py @@ -171,7 +171,7 @@ def onRemoveClozes(self): def checkModel(model, fields=True, notify=True): """Sanity checks for the model and fields""" - config = mw.col.conf["olcloze"] + config = loadConfig() mname = model["name"] is_olc = False # account for custom and imported note types: @@ -332,7 +332,8 @@ def onAddNote(self, note, _old): if not checkModel(note.model(), fields=False, notify=False): return oldret config = mw.col.conf["olcloze"] - if not config["sched"][2]: + sched_conf = config.get("sched", None) + if not sched_conf or not sched_conf[2]: return oldret maxfields = ClozeOverlapper.getMaxFields(note.model(), config["flds"]["tx"]) last = note.cards()[-1]