From 5bce218312af23858d894e4c3bcadbec58d82a76 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 27 Nov 2018 16:35:04 +1000 Subject: [PATCH] limit find&replace fields to selected notes --- anki/find.py | 13 +++++++++++++ aqt/browser.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/anki/find.py b/anki/find.py index cf658bbde..48d0dd1bd 100644 --- a/anki/find.py +++ b/anki/find.py @@ -539,6 +539,19 @@ def fieldNames(col, downcase=True): return list(fields) return names +def fieldNamesForNotes(col, nids): + downcasedNames = set() + origNames = [] + mids = col.db.list("select distinct mid from notes where id in %s" % ids2str(nids)) + for mid in mids: + model = col.models.get(mid) + for field in col.models.fieldNames(model): + if field.lower() not in downcasedNames: + downcasedNames.add(field.lower()) + origNames.append(field) + + return sorted(origNames, key=lambda x: x.lower()) + # Find duplicates ########################################################################## # returns array of ("dupestr", [nids]) diff --git a/aqt/browser.py b/aqt/browser.py index 544ffca2e..86816c006 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -1717,7 +1717,7 @@ update cards set usn=?, mod=?, did=? where id in """ + scids, if not sf: return import anki.find - fields = sorted(anki.find.fieldNames(self.col, downcase=False)) + fields = anki.find.fieldNamesForNotes(self.mw.col, sf) d = QDialog(self) frm = aqt.forms.findreplace.Ui_Dialog() frm.setupUi(d)