mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
fix tag editor
This commit is contained in:
parent
6a42ff99f0
commit
1cd108b86c
1 changed files with 5 additions and 8 deletions
|
@ -4,6 +4,7 @@
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
from anki.utils import parseTags, canonifyTags, joinTags
|
from anki.utils import parseTags, canonifyTags, joinTags
|
||||||
|
import re
|
||||||
|
|
||||||
class TagEdit(QLineEdit):
|
class TagEdit(QLineEdit):
|
||||||
|
|
||||||
|
@ -42,23 +43,19 @@ class TagCompleter(QCompleter):
|
||||||
self.edit = edit
|
self.edit = edit
|
||||||
|
|
||||||
def splitPath(self, str):
|
def splitPath(self, str):
|
||||||
str = unicode(str)
|
str = unicode(str).strip()
|
||||||
if str.strip().startswith(","):
|
str = re.sub(" +", " ", str)
|
||||||
self.cursor = 0
|
|
||||||
return QStringList("")
|
|
||||||
self.tags = parseTags(str)
|
self.tags = parseTags(str)
|
||||||
self.tags.append(u"")
|
self.tags.append(u"")
|
||||||
p = self.edit.cursorPosition()
|
p = self.edit.cursorPosition()
|
||||||
self.cursor = str.count(",", 0, p)
|
self.cursor = str.count(" ", 0, p)
|
||||||
return QStringList(self.tags[self.cursor])
|
return QStringList(self.tags[self.cursor])
|
||||||
|
|
||||||
def pathFromIndex(self, idx):
|
def pathFromIndex(self, idx):
|
||||||
ret = QCompleter.pathFromIndex(self, idx)
|
ret = QCompleter.pathFromIndex(self, idx)
|
||||||
if u"" not in self.tags:
|
|
||||||
self.tags.append(u"")
|
|
||||||
self.tags[self.cursor] = unicode(ret)
|
self.tags[self.cursor] = unicode(ret)
|
||||||
try:
|
try:
|
||||||
self.tags.remove(u"")
|
self.tags.remove(u"")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
return ", ".join(self.tags)
|
return " ".join(self.tags)
|
||||||
|
|
Loading…
Reference in a new issue