diff options
author | Yann Leboulanger <asterix@lagaule.org> | 2013-02-22 02:03:00 +0400 |
---|---|---|
committer | Yann Leboulanger <asterix@lagaule.org> | 2013-02-22 02:03:00 +0400 |
commit | b2ae21be0c2677792a7bd36672569d09a9a88d75 (patch) | |
tree | 29d0850f87c05276348d2739e09fb5e4647d2b96 /latex | |
parent | a5731e720249dbb75ad28105b74257c5b86cc7a5 (diff) |
improve latex detection by looking only in latest message. Fixes #49
Diffstat (limited to 'latex')
-rw-r--r-- | latex/latex.py | 53 | ||||
-rw-r--r-- | latex/manifest.ini | 2 |
2 files changed, 40 insertions, 15 deletions
diff --git a/latex/latex.py b/latex/latex.py index 10fbfa9..d5ed3ff 100644 --- a/latex/latex.py +++ b/latex/latex.py @@ -293,6 +293,8 @@ class LatexPlugin(GajimPlugin): self.disconnect_from_chat_control_base) } self.test_activatable() + self.timeout_id = None + self.last_eol_offset = -1 def test_activatable(self): """ @@ -360,24 +362,47 @@ class LatexPlugin(GajimPlugin): """ called when conversation text widget changes """ - def split_list(list): + def split_list(list_): newlist = [] - for i in range(0, len(list)-1, 2): - newlist.append( [ list[i], list[i+1], ] ) + for i in range(0, len(list_)-1, 2): + newlist.append( [ list_[i], list_[i+1], ] ) return newlist - assert isinstance(tb, Gtk.TextBuffer) - start_iter = tb.get_start_iter() - points = [] - tuple_found = start_iter.forward_search('$$', - Gtk.TextSearchFlags.TEXT_ONLY, None) - while tuple_found != None: - points.append(tuple_found) - tuple_found = tuple_found[1].forward_search('$$', + def detect_tags(tb, start_it=None, end_it=None): + self.timeout_id = None + if not end_it: + end_it = tb.get_end_iter() + if not start_it: + eol_tag = tb.get_tag_table().lookup('eol') + start_it = end_it.copy() + start_it.backward_to_tag_toggle(eol_tag) + points = [] + tuple_found = start_it.forward_search('$$', Gtk.TextSearchFlags.TEXT_ONLY, None) - - for pair in split_list(points): - tb.apply_tag_by_name('latex', pair[0][1], pair[1][0]) + while tuple_found != None: + points.append(tuple_found) + tuple_found = tuple_found[1].forward_search('$$', + Gtk.TextSearchFlags.TEXT_ONLY, None) + + for pair in split_list(points): + tb.apply_tag_by_name('latex', pair[0][1], pair[1][0]) + + end_iter = tb.get_end_iter() + eol_tag = tb.get_tag_table().lookup('eol') + it = end_iter.copy() + it.backward_to_tag_toggle(eol_tag) + if it.get_offset() == self.last_eol_offset: + if self.timeout_id: + GObject.source_remove(self.timeout_id) + self.timeout_id = Geobject.timeout_add(100, detect_tags, traceback, it, end_iter) + else: + if self.timeout_id: + GObject.source_remove(self.timeout_id) + it1 = it.copy() + it1.backward_char() + it1.backward_to_tag_toggle(eol_tag) + detect_tags(traceback, it1, it) + self.last_eol_offset = it.get_offset() def connect_with_chat_control_base(self, chat_control): d = {} diff --git a/latex/manifest.ini b/latex/manifest.ini index 88b1e94..e71ebdf 100644 --- a/latex/manifest.ini +++ b/latex/manifest.ini @@ -1,7 +1,7 @@ [info] name: Latex short_name: latex -version: 0.3 +version: 0.3.1 description: render received latex code authors: Yves Fischer <yvesf@xapek.org> Yann Leboulanger <asterix@lagaule.org> |