[meld] diffutil: New helper for whether a chunk still exists in the Differ



commit fe204cf05bec306a03d61c7bb3d69b42b451df39
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Jul 10 10:47:12 2016 +1000

    diffutil: New helper for whether a chunk still exists in the Differ
    
    This is useful for async calculations to make certain that the chunk
    that we have a result for is actually still valid. We do this check in
    a couple of different ways, but this one is necessary for when the
    text itself doesn't change but the chunk state does.

 meld/diffutil.py |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/meld/diffutil.py b/meld/diffutil.py
index 50f436c..c2552dd 100644
--- a/meld/diffutil.py
+++ b/meld/diffutil.py
@@ -244,6 +244,14 @@ class Differ(GObject.GObject):
                 return i
         return len(self.diffs[whichdiffs])
 
+    def has_chunk(self, to_pane, chunk):
+        """Return whether the pane/chunk exists in the current Differ"""
+        sequence = 1 if to_pane == 2 else 0
+        chunk_index, _, _ = self.locate_chunk(1, chunk.start_a)
+        if chunk_index is None:
+            return False
+        return self._merge_cache[chunk_index][sequence] == chunk
+
     def get_chunk(self, index, from_pane, to_pane=None):
         """Return the index-th change in from_pane
 


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