mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
canonify tags when saving, and strip quotes (#794)
This commit is contained in:
parent
e63c8e5619
commit
da66844f6b
2 changed files with 6 additions and 2 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
from anki.utils import intTime, ids2str, json
|
from anki.utils import intTime, ids2str, json
|
||||||
from anki.hooks import runHook
|
from anki.hooks import runHook
|
||||||
|
import re
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Anki maintains a cache of used tags so it can quickly present a list of tags
|
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):
|
def canonify(self, tagList):
|
||||||
"Strip duplicates and sort."
|
"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):
|
def inList(self, tag, tags):
|
||||||
"True if TAG is in TAGS. Ignore case."
|
"True if TAG is in TAGS. Ignore case."
|
||||||
|
|
|
@ -708,7 +708,9 @@ class Editor(object):
|
||||||
def saveTags(self):
|
def saveTags(self):
|
||||||
if not self.note:
|
if not self.note:
|
||||||
return
|
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:
|
if not self.addMode:
|
||||||
self.note.flush()
|
self.note.flush()
|
||||||
runHook("tagsUpdated", self.note)
|
runHook("tagsUpdated", self.note)
|
||||||
|
|
Loading…
Reference in a new issue