mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
don't allow tags of different cases
Previously they were allowed to be added, but all searches and operations treated them as case-sensitive, creating an inconsistency. The new implementation will change new tags with different case than existing ones to the version currently in the database. This may cause some slowdown in collections with a very large number of tags since the only way to do this at the moment is to scan through every one of them. Changing the format tags are stored in in the future may be useful.
This commit is contained in:
parent
04966d42b6
commit
b1e361bb32
1 changed files with 8 additions and 4 deletions
12
anki/tags.py
12
anki/tags.py
|
@ -37,8 +37,6 @@ class TagManager(object):
|
||||||
|
|
||||||
def register(self, tags, usn=None):
|
def register(self, tags, usn=None):
|
||||||
"Given a list of tags, add any missing ones to tag registry."
|
"Given a list of tags, add any missing ones to tag registry."
|
||||||
# case is stored as received, so user can create different case
|
|
||||||
# versions of the same tag if they ignore the qt autocomplete.
|
|
||||||
found = False
|
found = False
|
||||||
for t in tags:
|
for t in tags:
|
||||||
if t not in self.tags:
|
if t not in self.tags:
|
||||||
|
@ -145,8 +143,14 @@ class TagManager(object):
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def canonify(self, tagList):
|
def canonify(self, tagList):
|
||||||
"Strip duplicates and sort."
|
"Strip duplicates, adjust case to match existing tags, and sort."
|
||||||
strippedTags = [re.sub("[\"']", "", x) for x in tagList]
|
strippedTags = []
|
||||||
|
for t in tagList:
|
||||||
|
s = re.sub("[\"']", "", t)
|
||||||
|
for existingTag in self.tags:
|
||||||
|
if s.lower() == existingTag.lower():
|
||||||
|
s = existingTag
|
||||||
|
strippedTags.append(s)
|
||||||
return sorted(set(strippedTags))
|
return sorted(set(strippedTags))
|
||||||
|
|
||||||
def inList(self, tag, tags):
|
def inList(self, tag, tags):
|
||||||
|
|
Loading…
Reference in a new issue