Repository: tud-zih-energy/voice-annotation-tool (language: python)

Issue:
Pressing the next annotation shortcut selects multiple annotations
However the same does not happen when using the buttons.
This happens because changing the selection while pressing the control keys adds to the selection.


Discussion / hints:

Fix patch:
diff --git a/src/voice_annotation_tool/opened_project_frame.py b/src/voice_annotation_tool/opened_project_frame.py
index 5db2b3e..012bee8 100644
--- a/src/voice_annotation_tool/opened_project_frame.py
+++ b/src/voice_annotation_tool/opened_project_frame.py
@@ -157,12 +157,14 @@ def get_selected_annotations(self) -> List[Annotation]:
     def previous_pressed(self):
         current = self.annotationList.currentIndex().row()
         previous = self.annotationList.model().index(current - 1, 0)
+        self.annotationList.clearSelection()
         self.annotationList.setCurrentIndex(previous)
 
     @Slot()
     def next_pressed(self):
         current = self.annotationList.currentIndex().row()
         next = self.annotationList.model().index(current + 1, 0)
+        self.annotationList.clearSelection()
         self.annotationList.setCurrentIndex(next)
 
     @Slot()


Test patch:
diff --git a/test/test_opened_project.py b/test/test_opened_project.py
index f5af72f..a1a2af6 100644
--- a/test/test_opened_project.py
+++ b/test/test_opened_project.py
@@ -43,6 +43,24 @@ def test_tooltips_have_shortcuts(project_frame):
     play_button : QPushButton = project_frame.playPauseButton
     assert play_button.shortcut().toString() in play_button.toolTip()
 
+def test_next_button_selects_one(project_frame: OpenedProjectFrame):
+    project_frame.next_pressed()
+    assert len(project_frame.annotationList.selectedIndexes()) == 1
+
+def test_next_button_selects_correct_annotation(project_frame: OpenedProjectFrame):
+    project_frame.next_pressed()
+    assert project_frame.annotationList.selectedIndexes()[0].row() == 1
+
+def test_previous_button_selects_one(project_frame: OpenedProjectFrame):
+    project_frame.next_pressed()
+    project_frame.previous_pressed()
+    assert len(project_frame.annotationList.selectedIndexes()) == 1
+
+def test_previous_button_selects_correct_annotation(project_frame: OpenedProjectFrame):
+    project_frame.next_pressed()
+    project_frame.previous_pressed()
+    assert project_frame.annotationList.selectedIndexes()[0].row() == 0
+
 def test_mark_unchanged(project_frame: OpenedProjectFrame):
     project_frame.mark_unchanged_pressed()
     project_frame.mark_unchanged_pressed()