Fix a serialization bug (inversed tags)
This commit is contained in:
parent
9f0348c002
commit
13b2219223
@ -213,7 +213,4 @@ class WebActivity(activity.Activity):
|
|||||||
|
|
||||||
web_activity = WebActivity()
|
web_activity = WebActivity()
|
||||||
web_activity.activity_connect_to_shell()
|
web_activity.activity_connect_to_shell()
|
||||||
try:
|
gtk.main()
|
||||||
gtk.main()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
|
@ -128,24 +128,24 @@ class RichTextSerializer:
|
|||||||
if not next_it.forward_to_tag_toggle(None):
|
if not next_it.forward_to_tag_toggle(None):
|
||||||
next_it = buf.get_end_iter()
|
next_it = buf.get_end_iter()
|
||||||
|
|
||||||
reopen_tags = []
|
tags_to_reopen = []
|
||||||
|
|
||||||
for tag in it.get_toggled_tags(False):
|
for tag in it.get_toggled_tags(False):
|
||||||
while 1:
|
while 1:
|
||||||
open_tag = self._open_tags.pop()
|
open_tag = self._open_tags.pop()
|
||||||
if open_tag != tag:
|
xml += self.serialize_tag_end(tag)
|
||||||
xml += self.serialize_tag_end(open_tag)
|
if open_tag == tag:
|
||||||
reopen_tags.append(open_tag)
|
break
|
||||||
else:
|
tags_to_reopen.append(open_tag)
|
||||||
xml += self.serialize_tag_end(tag)
|
|
||||||
break
|
for tag in tags_to_reopen + it.get_toggled_tags(True):
|
||||||
|
|
||||||
for tag in reopen_tags + it.get_toggled_tags(True):
|
|
||||||
self._open_tags.append(tag)
|
self._open_tags.append(tag)
|
||||||
xml += self.serialize_tag_start(tag)
|
xml += self.serialize_tag_start(tag)
|
||||||
|
|
||||||
xml += buf.get_text(it, next_it)
|
xml += buf.get_text(it, next_it)
|
||||||
|
|
||||||
if next_it.is_end():
|
if next_it.is_end():
|
||||||
|
self._open_tags.reverse()
|
||||||
for tag in self._open_tags:
|
for tag in self._open_tags:
|
||||||
xml += self.serialize_tag_end(tag)
|
xml += self.serialize_tag_end(tag)
|
||||||
|
|
||||||
@ -171,8 +171,15 @@ if __name__ == "__main__":
|
|||||||
vbox = gtk.VBox()
|
vbox = gtk.VBox()
|
||||||
|
|
||||||
rich_buf = RichTextBuffer()
|
rich_buf = RichTextBuffer()
|
||||||
|
|
||||||
xml_string = "<richtext><bold><italic>Hello</italic>World</bold></richtext>"
|
xml_string = "<richtext>"
|
||||||
|
|
||||||
|
#xml_string += "<bold><italic>Test</italic>one</bold>\n"
|
||||||
|
xml_string += "<bold><italic>Test two</italic></bold>"
|
||||||
|
|
||||||
|
xml_string += "</richtext>"
|
||||||
|
|
||||||
|
|
||||||
RichTextSerializer().deserialize(xml_string, rich_buf)
|
RichTextSerializer().deserialize(xml_string, rich_buf)
|
||||||
|
|
||||||
view = gtk.TextView(rich_buf)
|
view = gtk.TextView(rich_buf)
|
||||||
|
Loading…
Reference in New Issue
Block a user