[meld] Don't queue highlighting tasks during user-actions (closes bgo#639027)



commit c6eede71fa7c2bd946e9871d74106fcbcf294708
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Jan 14 08:30:01 2011 +1000

    Don't queue highlighting tasks during user-actions (closes bgo#639027)
    
    While inline highlighting is expensive, repeated queueing of
    highlighting tasks is required to make sure that highlights stay
    up-to-date. However, we can reduce the number of tasks by delaying
    highlighting until after aggregate actions have completed. As an
    example, each replacement in a replace-all action should cause a change
    callback, but only the last action needs to queue a highlighting
    update. The delete/insert pairs from replace_chunk() are another
    example.
    
    This commit hooks into the existing user-action mechanism and
    suppresses calls to _update_highlighting() while inside a user action.

 meld/filediff.py |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index cd05c69..737ef84 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -215,6 +215,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         self._sync_hscroll_lock = False
         self.linediffer = self.differ()
         self.linediffer.ignore_blanks = self.prefs.ignore_blank_lines
+        self.in_nested_action = False
         self._inline_cache = set()
         self._cached_match = CachedSequenceMatcher()
         for buf in self.textbuffer:
@@ -518,7 +519,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             if focused_pane != -1:
                 self.on_cursor_position_changed(self.textbuffer[focused_pane],
                                                 None, True)
-            self.scheduler.add_task(self._update_highlighting().next)
+            self.update_highlighting()
             self.queue_draw()
 
     def _filter_text(self, txt):
@@ -680,10 +681,13 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         # text buffer undo/redo
         #
     def on_textbuffer__begin_user_action(self, *buffer):
+        self.in_nested_action = True
         self.undosequence.begin_group()
 
     def on_textbuffer__end_user_action(self, *buffer):
         self.undosequence.end_group()
+        self.in_nested_action = False
+        self.update_highlighting()
 
     def on_text_insert_text(self, buf, it, text, textlen):
         text = unicode(text, 'utf8')
@@ -926,7 +930,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         self.textbuffer[1].place_cursor(self.textbuffer[1].get_start_iter())
         self.scheduler.add_task(lambda: self.next_diff(gtk.gdk.SCROLL_DOWN), True)
         self.queue_draw()
-        self.scheduler.add_task(self._update_highlighting().next)
+        self.update_highlighting()
         self._connect_buffer_handlers()
         self._set_merge_action_sensitivity()
         for i in range(self.num_panes):
@@ -979,6 +983,10 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         for mgr in self.msgarea_mgr:
             mgr.clear()
 
+    def update_highlighting(self):
+        if not self.in_nested_action:
+            self.scheduler.add_task(self._update_highlighting().next)
+
     def _update_highlighting(self):
         alltexts = self.buffer_texts
         alltags = [b.get_tag_table().lookup("inline line") for b in self.textbuffer]



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]