[meld] Fix text filter changes not applying to existing comparisons



commit 604d4e211f7876bdb8dfce5bdfa94d7885751788
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Sep 2 08:05:27 2022 +1000

    Fix text filter changes not applying to existing comparisons
    
    This was caused by our caching of buffer lines (added in a15dbdfce2)
    because the BufferLines class can't tell when the filters it applies
    change. The easy fix here is to manually clear the line cache on
    comparison refresh, which is slightly over-zealous but probably fine in
    most cases.
    
    A better solution here would be to have the filters passed in to the
    BufferLines class either be immutable or have a changed signal that
    the class could connect to to do this cache invalidation on its own.

 meld/filediff.py   | 2 ++
 meld/meldbuffer.py | 3 +++
 2 files changed, 5 insertions(+)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 5dde307d..d2987749 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1538,6 +1538,8 @@ class FileDiff(Gtk.VBox, MeldDoc):
     def pre_comparison_init(self):
         self._disconnect_buffer_handlers()
         self.linediffer.clear()
+        for bufferlines in self.buffer_filtered:
+            bufferlines.clear_cache()
 
         for buf in self.textbuffer:
             tag = buf.get_tag_table().lookup("inline")
diff --git a/meld/meldbuffer.py b/meld/meldbuffer.py
index 106a1dbd..d7b5bdb6 100644
--- a/meld/meldbuffer.py
+++ b/meld/meldbuffer.py
@@ -248,6 +248,9 @@ class BufferLines:
                 f"{len(self.lines)} != {len(self)}",
             )
 
+    def clear_cache(self) -> None:
+        self.lines = [None] * self.buf.get_line_count()
+
     def on_insert_text(self, buf, it, text, textlen):
         buf.move_mark(self.mark, it)
 


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