mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 22:42:25 -04:00
when renaming a field, support cloze: as well
This commit is contained in:
parent
68da292ddb
commit
62b44df78e
1 changed files with 8 additions and 9 deletions
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue