canonify tags when saving, and strip quotes (#794)

This commit is contained in:
Damien Elmes 2013-05-17 13:51:49 +09:00
parent e63c8e5619
commit da66844f6b
2 changed files with 6 additions and 2 deletions

View file

@ -4,6 +4,7 @@
from anki.utils import intTime, ids2str, json
from anki.hooks import runHook
import re
"""
Anki maintains a cache of used tags so it can quickly present a list of tags
@ -145,7 +146,8 @@ class TagManager(object):
def canonify(self, tagList):
"Strip duplicates and sort."
return sorted(set(tagList))
strippedTags = [re.sub("[\"']", "", x) for x in tagList]
return sorted(set(strippedTags))
def inList(self, tag, tags):
"True if TAG is in TAGS. Ignore case."

View file

@ -708,7 +708,9 @@ class Editor(object):
def saveTags(self):
if not self.note:
return
self.note.tags = self.mw.col.tags.split(self.tags.text())
self.note.tags = self.mw.col.tags.canonify(
self.mw.col.tags.split(self.tags.text()))
self.tags.setText(self.mw.col.tags.join(self.note.tags).strip())
if not self.addMode:
self.note.flush()
runHook("tagsUpdated", self.note)