Fix move rows bug

Fixes #244
This commit is contained in:
Keith Edmunds 2024-05-22 15:26:57 +01:00
parent a7932adfe4
commit fc4129994b
2 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -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