Skip to content

Commit

Permalink
fixed: groups cannot be dragged to the end
Browse files Browse the repository at this point in the history
  • Loading branch information
oxdc committed Oct 29, 2024
1 parent 33b72f8 commit 8388dde
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/NavigationContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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);
}
}
}
};
Expand Down
9 changes: 9 additions & 0 deletions src/models/TabCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,6 +119,14 @@ export const useTabCache = create<TabCacheStore>()((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 });
Expand Down

0 comments on commit 8388dde

Please sign in to comment.