Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(split): allow open split to the left (#4393)

Seamusfb210fc63d54
diff --git a/js/app/packages/app/component/split-layout/components/SplitHeader.tsx b/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
index ae7d61a2ac..f8d094dd80 100644
--- a/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitHeader.tsx
@@ -13,6 +13,7 @@ import { TOKENS } from '@core/hotkey/tokens';
import { isMobile } from '@core/mobile/isMobile';
import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';
import type { EntityDragEvent } from '@entity';
+import SplitIcon from '@icon/wide-newSplit.svg';
import { ContextMenu } from '@kobalte/core/context-menu';
import ArrowClockwise from '@phosphor/arrow-clockwise.svg';
import CollapseIcon from '@phosphor/arrows-in.svg';
@@ -22,7 +23,6 @@ import CaretLeft from '@phosphor/caret-left.svg';
import CaretRight from '@phosphor/caret-right.svg';
import CaretUp from '@phosphor/caret-up.svg';
import CopyIcon from '@phosphor/copy.svg';
-import SplitIcon from '@phosphor/square-half.svg';
import CloseIcon from '@phosphor/x.svg';
import { mergeRefs } from '@solid-primitives/refs';
import { createDroppable, useDragDropContext } from '@thisbeyond/solid-dnd';
@@ -252,15 +252,15 @@ function SplitHeaderContextMenu(props: ParentProps) {
const index = splitIndex();
if (index < 0) return;
- const nextContents = layout.manager
- .splits()
- .map((split) => ({ ...split.content }));
const insertIndex = side === 'left' ? index : index + 1;
- nextContents.splice(insertIndex, 0, content);
- layout.manager.reconcile(nextContents);
- layout.manager.splits()[insertIndex]?.id &&
- layout.manager.activateSplit(layout.manager.splits()[insertIndex].id);
+ layout.manager.createNewSplit({
+ content,
+ activate: true,
+ allowDuplicate: true,
+ insertIndex,
+ referredFrom: null,
+ });
};
const copyDebugInfo = async () => {
@@ -301,6 +301,7 @@ function SplitHeaderContextMenu(props: ParentProps) {
<ContextMenuContent width="md">
<MenuItem
icon={SplitIcon}
+ iconClass="rotate-180"
text="New split left"
disabled={!layout.manager.canAppendSplit()}
onClick={() => insertSplitBeside('left', newSplitContent())}
diff --git a/js/app/packages/app/component/split-layout/layout.ts b/js/app/packages/app/component/split-layout/layout.ts
index b3793de056..f326220754 100644
--- a/js/app/packages/app/component/split-layout/layout.ts
+++ b/js/app/packages/app/component/split-layout/layout.ts
@@ -63,12 +63,14 @@ export function useSplitLayout() {
function insertSplit(
content: SplitContent,
- referredFrom: ReferredFrom = null
+ referredFrom: ReferredFrom = null,
+ options: Pick<OpenWithSplitOptions, 'insertIndex'> = {}
) {
return openWithSplit(content, {
activate: true,
referredFrom,
preferNewSplit: true,
+ ...options,
});
}
diff --git a/js/app/packages/app/component/split-layout/layoutManager.ts b/js/app/packages/app/component/split-layout/layoutManager.ts
index 02967b25cd..d9ef6d06fa 100644
--- a/js/app/packages/app/component/split-layout/layoutManager.ts
+++ b/js/app/packages/app/component/split-layout/layoutManager.ts
@@ -151,6 +151,7 @@ export type CreateNewSplitOptions = {
activate?: boolean;
allowDuplicate?: boolean;
referredFrom: ReferredFrom;
+ insertIndex?: number;
/**
* Optional prior navigation entries to pre-populate this split's history stack.
* The `content` field is appended as the final (current) entry.
@@ -166,6 +167,7 @@ export type OpenWithSplitOptions = {
replaceWhenFull?: boolean;
/** If true, prefers opening in a new split. May still replace if layout is at capacity. */
preferNewSplit?: boolean;
+ insertIndex?: number;
handle?: SplitHandle;
};
@@ -989,8 +991,14 @@ export function createSplitLayout(
};
function createNewSplit(options: CreateNewSplitOptions): SplitHandle {
- const { content, activate, referredFrom, allowDuplicate, initialHistory } =
- options;
+ const {
+ content,
+ activate,
+ referredFrom,
+ allowDuplicate,
+ initialHistory,
+ insertIndex,
+ } = options;
const initialContent = content ?? DEFAULT_SPLIT_CONTENT;
const isDefault = sameContent(initialContent, DEFAULT_SPLIT_CONTENT);
@@ -1014,7 +1022,17 @@ export function createSplitLayout(
initialHistory,
});
- setState('splits', (previousSplits) => [...previousSplits, split]);
+ setState('splits', (previousSplits) => {
+ if (insertIndex === undefined) return [...previousSplits, split];
+
+ const nextSplits = [...previousSplits];
+ nextSplits.splice(
+ Math.max(0, Math.min(insertIndex, nextSplits.length)),
+ 0,
+ split
+ );
+ return nextSplits;
+ });
const handle = getSplit(split.id)!;
@@ -1276,6 +1294,7 @@ export function createSplitLayout(
activate: options.activate ?? true,
referredFrom: options.referredFrom ?? null,
allowDuplicate: options.allowDuplicate,
+ insertIndex: options.insertIndex,
});
}
}
diff --git a/js/app/packages/app/component/split-layout/tests/layoutManager.test.ts b/js/app/packages/app/component/split-layout/tests/layoutManager.test.ts
index f773301031..f924fcf39b 100644
--- a/js/app/packages/app/component/split-layout/tests/layoutManager.test.ts
+++ b/js/app/packages/app/component/split-layout/tests/layoutManager.test.ts
@@ -154,4 +154,58 @@ describe('layoutManager', () => {
});
});
});
+
+ describe('indexed insertion', () => {
+ it('creates a split at the requested index', () => {
+ createRoot((dispose) => {
+ const manager = createSplitLayout(createMockOrchestrator(), [
+ { type: 'md', id: 'left' },
+ { type: 'md', id: 'right' },
+ ]);
+
+ const inserted = manager.createNewSplit({
+ content: { type: 'component', id: 'unified-list' },
+ activate: true,
+ referredFrom: null,
+ insertIndex: 1,
+ });
+
+ expect(manager.splits().map((split) => split.content.id)).toEqual([
+ 'left',
+ 'unified-list',
+ 'right',
+ ]);
+ expect(manager.activeSplitId()).toBe(inserted.id);
+
+ dispose();
+ });
+ });
+
+ it('opens duplicate content at the requested index when duplicates are allowed', () => {
+ createRoot((dispose) => {
+ const manager = createSplitLayout(createMockOrchestrator(), [
+ { type: 'component', id: 'unified-list' },
+ { type: 'md', id: 'current' },
+ ]);
+
+ const inserted = manager.openWithSplit(
+ { type: 'component', id: 'unified-list' },
+ {
+ allowDuplicate: true,
+ preferNewSplit: true,
+ insertIndex: 1,
+ }
+ );
+
+ expect(manager.splits().map((split) => split.content.id)).toEqual([
+ 'unified-list',
+ 'unified-list',
+ 'current',
+ ]);
+ expect(manager.activeSplitId()).toBe(inserted?.id);
+
+ dispose();
+ });
+ });
+ });
});
diff --git a/js/app/packages/icon/wide-newSplit.svg b/js/app/packages/icon/wide-newSplit.svg
index c4faedb938..343e35eca1 100644
--- a/js/app/packages/icon/wide-newSplit.svg
+++ b/js/app/packages/icon/wide-newSplit.svg
@@ -1,5 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.125" stroke-linecap="round" stroke-linejoin="round">
<rect x="9.5625" y="2.0625" width="6.375" height="13.875" rx="1.5"/>
- <line x1="1.5" y1="9" x2="7.5" y2="9"/>
<line x1="4.5" y1="6" x2="4.5" y2="12"/>
</svg>