From b4362dd96851ac45acce4c79d63fc62c370bbea6 Mon Sep 17 00:00:00 2001 From: lawvs <18554747+lawvs@users.noreply.github.com> Date: Mon, 25 Jul 2022 18:21:37 +0800 Subject: [PATCH] fix(kanban): move kanban card at same group (#524) --- libs/components/editor-core/src/kanban/kanban.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/components/editor-core/src/kanban/kanban.ts b/libs/components/editor-core/src/kanban/kanban.ts index 096a5239d..d47e0ce75 100644 --- a/libs/components/editor-core/src/kanban/kanban.ts +++ b/libs/components/editor-core/src/kanban/kanban.ts @@ -278,7 +278,11 @@ export const useKanban = () => { // 1.1 Target group is not specified, just set the nowGroup as the targetGroup targetGroup = nowGroup; } - if (nowGroup.id !== targetGroup.id) { + const isChangedGroup = nowGroup.id !== targetGroup.id; + const previousIdx = nowGroup.items.findIndex( + card => card.id === targetCard.id + ); + if (isChangedGroup) { // 1.2 Move to the target group await moveCardToGroup(groupBy.id, targetCard, targetGroup); } @@ -297,6 +301,10 @@ export const useKanban = () => { await moveCardToBefore(targetCard, nowGroup.items[0].block); return; } + // Fix move card from idx 0 to idx 1 at same group + if (!isChangedGroup && previousIdx < idx && previousIdx !== -1) { + idx++; + } if (idx > nowGroup.items.length) { idx = nowGroup.items.length; }