Skip to content

Commit

Permalink
added isSelfTheOnlyChildOfGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
oxdc committed Sep 16, 2024
1 parent 267ceb4 commit e25e61a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/components/NavigationContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { SortableContext } from "@dnd-kit/sortable";
import { createPortal } from "react-dom";
import * as VT from "src/models/VTWorkspace";
import {
isSelfContainedInGroup,
isSelfTheOnlyChildOfGroup,
moveTab,
moveTabToEnd,
moveTabToNewGroup,
Expand Down Expand Up @@ -102,13 +102,6 @@ export const NavigationContent = () => {
return content.get(groupID);
};

const hasOnlySelf = (groupID: VT.Identifier): boolean => {
return (
isSelfContainedInGroup(app, groupID) &&
content.get(groupID).leafIDs.length == 1
);
};

return (
<div className={toClassName(rootContainerClasses)}>
<div className={toClassName(containerClasses)}>
Expand All @@ -120,7 +113,8 @@ export const NavigationContent = () => {
>
<SortableContext items={getGroupIDs()}>
{groupIDs.map((groupID) =>
hasOnlySelf(groupID) && excludeSelf ? null : (
isSelfTheOnlyChildOfGroup(app, groupID) &&
excludeSelf ? null : (
<Group
key={groupID}
type={entryOf(groupID).groupType}
Expand Down
11 changes: 11 additions & 0 deletions src/services/MoveTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ export function isSelfContainedInGroup(
return self.parent?.id === groupID;
}

export function isSelfTheOnlyChildOfGroup(
app: App,
groupID: VT.Identifier
): boolean {
const leaves = app.workspace.getLeavesOfType(VIEW_TYPE);
if (leaves.length === 0) return false;
const self = leaves[0] as VT.WorkspaceLeaf;
const parent = self.parent as VT.WorkspaceParent;
return self.parent?.id === groupID && parent.children.length === 1;
}

export async function moveSelfToDefaultLocation(app: App) {
const workspace = app.workspace as VT.Workspace;
const leaves = workspace.getLeavesOfType(VIEW_TYPE);
Expand Down

0 comments on commit e25e61a

Please sign in to comment.