From 8388ddece405f7ab85476ee1c2cfb231771f59d4 Mon Sep 17 00:00:00 2001 From: oxdc <29519076+oxdc@users.noreply.github.com> Date: Tue, 29 Oct 2024 22:25:09 +0800 Subject: [PATCH] fixed: groups cannot be dragged to the end --- src/components/NavigationContent.tsx | 8 ++++++-- src/models/TabCache.ts | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/NavigationContent.tsx b/src/components/NavigationContent.tsx index f02b301..7e8b2fa 100644 --- a/src/components/NavigationContent.tsx +++ b/src/components/NavigationContent.tsx @@ -23,7 +23,7 @@ import { GroupSlot } from "./GroupSlot"; import { Identifier } from "src/models/VTWorkspace"; export const NavigationContent = () => { - const { groupIDs, content, swapGroup } = useTabCache(); + const { groupIDs, content, swapGroup, moveGroupToEnd } = useTabCache(); const app = useApp(); const sensors = useSensors( useSensor(PointerSensor, { @@ -70,7 +70,11 @@ export const NavigationContent = () => { if (!leaf) return; swapGroup(activeID, leaf.parent.id); } else { - swapGroup(activeID, overID); + if (overID === "slot-new") { + moveGroupToEnd(activeID); + } else { + swapGroup(activeID, overID); + } } } }; diff --git a/src/models/TabCache.ts b/src/models/TabCache.ts index 5aa2f57..b9c3ad4 100644 --- a/src/models/TabCache.ts +++ b/src/models/TabCache.ts @@ -38,6 +38,7 @@ interface TabCacheStore { clear: () => void; refresh: (app: App) => void; swapGroup: (source: Identifier, target: Identifier) => void; + moveGroupToEnd: (groupID: Identifier) => void; setSortStrategy: (strategy: SortStrategy | null) => void; sort: () => void; hasOnlyOneGroup: () => boolean; @@ -118,6 +119,14 @@ export const useTabCache = create()((set, get) => ({ set({ groupIDs }); saveGroupOrder(groupIDs); }, + moveGroupToEnd: (groupID) => { + const { groupIDs } = get(); + const index = groupIDs.indexOf(groupID); + groupIDs.splice(index, 1); + groupIDs.push(groupID); + set({ groupIDs }); + saveGroupOrder(groupIDs); + }, setSortStrategy: (strategy) => { saveSortStrategy(strategy); set({ sortStrategy: strategy });