[meld] chunkmap: Improve responsiveness when dragging in ChunkMap



commit 817215c49f50f91ec2fca178f8e0217ce3932e30
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Aug 8 09:07:31 2021 +1000

    chunkmap: Improve responsiveness when dragging in ChunkMap
    
    The default behaviour here is to use the GTK scrolling helpers when
    e.g., clicking in the map, so that we get nice animated scrolling to a
    point. However, this feels very bad when dragging in the ChunkMap,
    because the animated delays make the dragging feel very sluggish. Here,
    we're doing the simple thing when we're in a drag state and just setting
    the adjustment value directly.

 meld/chunkmap.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/meld/chunkmap.py b/meld/chunkmap.py
index 1f295609..a19c9425 100644
--- a/meld/chunkmap.py
+++ b/meld/chunkmap.py
@@ -207,7 +207,7 @@ class ChunkMap(Gtk.DrawingArea):
     def _scroll_to_location(self, location: float):
         raise NotImplementedError()
 
-    def _scroll_fraction(self, position: float):
+    def _scroll_fraction(self, position: float, *, animate: bool = True):
         """Scroll the mapped textview to the given position
 
         This uses GtkTextView's scrolling so that the movement is
@@ -223,7 +223,10 @@ class ChunkMap(Gtk.DrawingArea):
         adj = self.adjustment
         location = fraction * (adj.get_upper() - adj.get_lower())
 
-        self._scroll_to_location(location)
+        if animate:
+            self._scroll_to_location(location)
+        else:
+            adj.set_value(location)
 
     def do_button_press_event(self, event: Gdk.EventButton) -> bool:
         if event.button == 1:
@@ -244,7 +247,7 @@ class ChunkMap(Gtk.DrawingArea):
 
     def do_motion_notify_event(self, event: Gdk.EventMotion) -> bool:
         if self._have_grab:
-            self._scroll_fraction(event.y)
+            self._scroll_fraction(event.y, animate=False)
 
         return True
 


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