improve latex detection by looking only in latest message. Fixes #49
This commit is contained in:
@@ -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)
|
||||
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])
|
||||
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 = {}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user