diff --git a/publish/changeLog.md b/publish/changeLog.md index 86e4252d..c9331ea6 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -10,4 +10,4 @@ - 修复某些情况下开放 API 获取到的音量为 0 的问题 (#2790) - 修复 mg 图片、歌词获取 - 修复某些 tx 歌单打开失败的问题 (#1060, @ght-000) -- 修复在某些情况下添加歌曲时可能导致保存的歌曲顺序不对的问题(#2842) +- 修复在某些情况下添加、移动歌曲时可能导致保存的歌曲顺序不对的问题(#2842) diff --git a/src/main/worker/dbService/modules/list/index.ts b/src/main/worker/dbService/modules/list/index.ts index 8f283d8f..79214d38 100644 --- a/src/main/worker/dbService/modules/list/index.ts +++ b/src/main/worker/dbService/modules/list/index.ts @@ -275,10 +275,14 @@ export const musicsMove = (fromId: string, toId: string, musicInfos: LX.Music.Mu arrUnshift(toList, musicInfos) break case 'bottom': - default: - moveMusicInfo(fromId, ids, toDBMusicInfo(musicInfos, toId, toList.length)) + default:{ + // 如果是添加到最后,那么取最后一个歌曲的原始位置 + 1 作为新歌曲的原始位置,否则新歌曲的原始位置为 position + // 因为原始 pos 可能比 targetList.length 大,所以不能直接用 targetList.length 作为新歌曲的原始位置 + const order = toList.length ? (getMusicInfoOrder(toId, toList.at(-1)!.id)?.order ?? toList.length) + 1 : 0 + moveMusicInfo(fromId, ids, toDBMusicInfo(musicInfos, toId, order)) arrPush(toList, musicInfos) break + } } listSet = new Set(ids)