Browse files

HTML normalisation when testing if a field has changed

  • Loading branch information...
batterseapower committed Feb 11, 2010
1 parent 141116a commit 5b852332abaa497c06fee4accd1b82baea27c6bd
Showing with 11 additions and 1 deletion.
  1. +11 −1 pinyin/anki/
@@ -87,10 +87,20 @@ def onFocusLost(self, fact, field):
if not self.sessionExistsFor(field):
+ # This is necessary because the QT controls screw with the HTML. If we don't normalise
+ # away the changes before the comparison, we might report changes where none took place.
+ def normaliseHtml(html):
+ if html == None:
+ return None
+ te = QtGui.QTextEdit()
+ te.setHtml(html)
+ return te.toHtml()
+"User moved focus from the field %s",
# Check old field contents against remembered value to determine changed status..
- self.knownfieldcontents[], fieldchanged = None, self.knownfieldcontents[] != field.value
+ self.knownfieldcontents[], fieldchanged = None, normaliseHtml(self.knownfieldcontents[]) != normaliseHtml(field.value)
# Changed fields have their "generated" tag stripped. NB: ALWAYS update the fact (even if the
# field hasn't changed) because we might have changed ANOTHER field to e.g. blank it, and now

0 comments on commit 5b85233

Please sign in to comment.