when renaming a field, support cloze: as well

This commit is contained in:
Damien Elmes 2012-04-22 08:01:17 +09:00
parent 68da292ddb
commit 62b44df78e

View file

@ -264,16 +264,15 @@ select id from cards where nid in (select id from notes where mid = ?)""",
def renameField(self, m, field, newName): def renameField(self, m, field, newName):
self.col.modSchema() self.col.modSchema()
pat = "({{|[:#^/])%s(}})"
for t in m['tmpls']: for t in m['tmpls']:
types = ("{{%s}}", "{{text:%s}}", "{{#%s}}", for fmt in ('qfmt', 'afmt'):
"{{^%s}}", "{{/%s}}") if newName:
for type in types: t[fmt] = re.sub(
for fmt in ('qfmt', 'afmt'): pat % field['name'], "\\1%s\\2" % newName, t[fmt])
if newName: else:
repl = type%newName t[fmt] = re.sub(
else: pat % field['name'], "", t[fmt])
repl = ""
t[fmt] = t[fmt].replace(type%field['name'], repl)
field['name'] = newName field['name'] = newName
self.save(m) self.save(m)