[meld] Add a helper function in killit for offset calculations



commit f25d0b3415a477a87211d411e6dc383aa7c50ba0
Author: David Rabel <David Rabel NoreSoft com>
Date:   Sun Nov 8 09:29:35 2015 +0100

    Add a helper function in killit for offset calculations
    
    In commit cef0f70c3f77c3a83c8b3807671ef76e292a0768 we added
    visual indication for filtered text.
    
    The patch contained duplicate code and was a little bit unclear.
    
    This fix contains a helper function to clean it up a bit.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=633515

 meld/filediff.py |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 301b316..c2117a8 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -765,31 +765,31 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
     def _filter_text(self, txt, buf, start_iter, end_iter):
         dimmed_tag = buf.get_tag_table().lookup("dimmed")
         buf.remove_tag(dimmed_tag, start_iter, end_iter)
-        start = start_iter.copy()
-        end = start_iter.copy()
 
         def killit(m):
+
+            def get_match_iters(match, match_index=0):
+                start = start_iter.copy()
+                end = start_iter.copy()
+                start.forward_chars(match.start(match_index))
+                end.forward_chars(match.end(match_index))
+                return start, end
+
             assert m.group().count("\n") == 0
             if len(m.groups()):
                 s = m.group()
                 for i in reversed(range(1, len(m.groups())+1)):
                     g = m.group(i)
                     if g:
-                        start.forward_chars(m.start(i))
-                        end.forward_chars(m.end(i))
+                        start, end = get_match_iters(m, i)
                         buf.apply_tag(dimmed_tag, start, end)
-                        start.forward_chars(-m.start(i))
-                        end.forward_chars(-m.end(i))
 
                         s = s[:m.start(i)-m.start()]+s[m.end(i)-m.start():]
 
                 return s
             else:
-                start.forward_chars(m.start())
-                end.forward_chars(m.end())
+                start, end = get_match_iters(m)
                 buf.apply_tag(dimmed_tag, start, end)
-                start.forward_chars(-m.start())
-                end.forward_chars(-m.end())
 
                 return ""
 


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