[meld] filediff: Update filter logic for multiple groups in matches



commit 9d258138caf1376130be0d05d64991337b1aebf7
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Dec 6 09:01:59 2015 +1000

    filediff: Update filter logic for multiple groups in matches

 meld/filediff.py |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index dafa69b..d456962 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -769,10 +769,20 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         try:
             filter_ranges = []
 
-            for filt in self.text_filters:
-                if filt.active:
-                    for match in filt.filter.finditer(txt):
+            active_filters = [f for f in self.text_filters if f.active]
+            for filt in active_filters:
+                for match in filt.filter.finditer(txt):
+                    # If there are no groups in the match, use the whole match
+                    if not filt.filter.groups:
                         filter_ranges.append(match.span())
+                        continue
+
+                    # If there are groups in the regex, include all groups that
+                    # participated in the match
+                    for i in range(filt.filter.groups):
+                        span = match.span(i + 1)
+                        if span != (-1, -1):
+                            filter_ranges.append(span)
 
             filter_ranges = misc.merge_intervals(filter_ranges)
 


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