diff --git a/app/playlistmodel.py b/app/playlistmodel.py index 21941d4..6798be9 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -831,26 +831,27 @@ class PlaylistModel(QAbstractTableModel): # endRemoveRows and the row range must be contiguous. Process # the highest rows first so the lower row numbers are unchanged row_groups = self._reversed_contiguous_row_groups(from_rows) - next_to_row = to_row_number # Prepare destination playlist for a reset self.signals.begin_reset_model_signal.emit(to_playlist_id) with db.Session() as session: - # Make room in destination playlist - max_destination_row_number = PlaylistRows.get_last_used_row( - session, to_playlist_id - ) - if ( - max_destination_row_number - and to_row_number <= max_destination_row_number - ): - # Move the destination playlist rows down to make room. - PlaylistRows.move_rows_down( - session, to_playlist_id, to_row_number, len(from_rows) - ) for row_group in row_groups: + # Make room in destination playlist + max_destination_row_number = PlaylistRows.get_last_used_row( + session, to_playlist_id + ) + if ( + max_destination_row_number + and to_row_number <= max_destination_row_number + ): + # Move the destination playlist rows down to make room. + PlaylistRows.move_rows_down( + session, to_playlist_id, to_row_number, len(row_group) + ) + next_to_row = to_row_number + super().beginRemoveRows(QModelIndex(), min(row_group), max(row_group)) for playlist_row in PlaylistRows.plrids_to_plrs( session, diff --git a/tests/test_playlistmodel.py b/tests/test_playlistmodel.py index eddc8f9..42778c0 100644 --- a/tests/test_playlistmodel.py +++ b/tests/test_playlistmodel.py @@ -387,9 +387,9 @@ class TestMMMiscRowMove(unittest.TestCase): assert [int(a) for a in row_notes] == [ 0, 1, + 1, 3, 4, - 1, 2, 3, 4,