[pitivi] timeline: Fix ctrl+click clears whole selection



commit 7f32cf27e0ea96f9390ab4af750473a3d49c7bc6
Author: Thejas Kiran P S <thejaskiranps gmail com>
Date:   Thu Jun 16 21:18:15 2022 +0530

    timeline: Fix ctrl+click clears whole selection
    
    set_selection() was called after we created a temporary GES.Group
    which is used to hold selection elements. This temporary group was
    interfering with our selection logic and caused this bug. Now the
    group is created only when the mouse starts moving.
    
    Fixes #2433

 pitivi/timeline/timeline.py     |  3 ++-
 tests/test_timeline_timeline.py | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index a9af20e94..9cb506566 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -744,7 +744,6 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
             if self.dragging_element:
                 self.__drag_start_x = event.x
                 self._on_layer = self.dragging_element.layer.ges_layer
-                self.dragging_group = self.selection.group()
             else:
                 layer_controls = self._get_parent_of_type(event_widget, LayerControls)
                 if layer_controls:
@@ -871,6 +870,8 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
 
     def _motion_notify_event_cb(self, unused_widget, event):
         if self.dragging_element:
+            if self.dragging_group is None:
+                self.dragging_group = self.selection.group()
             if isinstance(self.dragging_element, TransitionClip) and \
                     not self.__clicked_handle:
                 # Don't allow dragging a transition.
diff --git a/tests/test_timeline_timeline.py b/tests/test_timeline_timeline.py
index 6f874b731..f26591394 100644
--- a/tests/test_timeline_timeline.py
+++ b/tests/test_timeline_timeline.py
@@ -683,7 +683,7 @@ class TestEditing(common.TestCase):
                          "No new layer should have been created")
 
 
-class TestShiftSelection(common.TestCase):
+class TestClipsSelection(common.TestCase):
 
     def __reset_clips_selection(self, timeline):
         """Unselects all clips in the timeline."""
@@ -850,6 +850,36 @@ class TestShiftSelection(common.TestCase):
         self.__check_shift_selection_multiple_layers(left_click_also_seeks=False)
         self.__check_shift_selection_multiple_layers(left_click_also_seeks=True)
 
+    def test_clip_unselection(self):
+        """Tests whether the clips are unselected properly."""
+        timeline = common.create_timeline_container().timeline
+
+        clip1, clip2 = self.add_clips_simple(timeline, 2)
+        self.click_clip(clip1, expect_selected=True, ctrl_key=True)
+        self.click_clip(clip2, expect_selected=True, ctrl_key=True)
+        self.__check_selected([clip1, clip2], [])
+
+        # Unselect clip2.
+        self.click_clip(clip2, expect_selected=False, ctrl_key=True)
+        self.__check_selected([clip1], [clip2])
+
+    def test_grouped_clips_unselection(self):
+        """Tests grouped clips are unselected together."""
+        timeline_container = common.create_timeline_container()
+        timeline = timeline_container.timeline
+
+        clip1, clip2, clip3 = self.add_clips_simple(timeline, 3)
+        self.click_clip(clip1, expect_selected=True, ctrl_key=True)
+        self.click_clip(clip2, expect_selected=True, ctrl_key=True)
+        timeline_container.group_action.activate()
+
+        self.click_clip(clip3, expect_selected=True, ctrl_key=True)
+        self.__check_selected([clip1, clip2, clip3], [])
+
+        # Unselect the group.
+        self.click_clip(clip1, expect_selected=False, ctrl_key=True)
+        self.__check_selected([clip3], [clip1, clip2])
+
 
 class TestTimelineContainer(common.TestCase):
     """Tests for the TimelineContainer class."""


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