From fc4129994be82b690547ab029f45e89aadd4e1db Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Wed, 22 May 2024 15:26:57 +0100 Subject: [PATCH] Fix move rows bug Fixes #244 --- app/playlistmodel.py | 2 +- tests/test_playlistmodel.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/playlistmodel.py b/app/playlistmodel.py index 4d16088..b23b984 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -862,7 +862,7 @@ class PlaylistModel(QAbstractTableModel): # otherwise rows below the destination row will end up above the # moved rows. adjusted_to_row = to_row_number - len( - [a for a in from_rows if a <= to_row_number] + [a for a in from_rows if a < to_row_number] ) # Put the from_row row numbers into the row_map. Ultimately the diff --git a/tests/test_playlistmodel.py b/tests/test_playlistmodel.py index cfb5c45..2a5f227 100644 --- a/tests/test_playlistmodel.py +++ b/tests/test_playlistmodel.py @@ -244,6 +244,20 @@ class TestMMMiscRowMove(unittest.TestCase): new_order.append(int(self.model.playlist_rows[row].note)) assert new_order == [0, 1, 2, 3, 4, 7, 8, 10, 5, 6, 9] + def test_move_rows_test9(self): + # move rows [1, 2, 3] → 0 + # Replicate issue 244 + + self.model.move_rows([0, 1, 2, 3], 0) + + # Check we have all rows and plr_rownums are correct + new_order = [] + for row in range(self.model.rowCount()): + assert row in self.model.playlist_rows + assert self.model.playlist_rows[row].plr_rownum == row + new_order.append(int(self.model.playlist_rows[row].note)) + assert new_order == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + def test_insert_header_row_end(self): # insert header row at end of playlist