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(splits): resizer breaking split ordering integrity on history navigation (#2104)

teo3e76b2b2a3af
diff --git a/js/app/packages/core/component/Resize/solver.test.ts b/js/app/packages/core/component/Resize/solver.test.ts
new file mode 100644
index 0000000000..a591ae2b63
--- /dev/null
+++ b/js/app/packages/core/component/Resize/solver.test.ts
@@ -0,0 +1,84 @@
+import { createRoot } from 'solid-js';
+import { describe, expect, it } from 'vitest';
+import { createResizeSolver } from './solver';
+
+describe('createResizeSolver', () => {
+ describe('addPanel', () => {
+ it('should insert a panel at index 0 when index=0 is passed', () => {
+ createRoot((dispose) => {
+ const solver = createResizeSolver({
+ direction: 'horizontal',
+ gutter: () => 4,
+ size: () => 1000,
+ panels: [{ id: 'A', minSize: 100, maxSize: Infinity }],
+ });
+
+ expect(solver.order()).toEqual(['A']);
+
+ // Insert "B" at index 0 — should go BEFORE "A"
+ solver.addPanel({ id: 'B', minSize: 100, maxSize: Infinity }, 0);
+
+ expect(solver.order()).toEqual(['B', 'A']);
+
+ dispose();
+ });
+ });
+
+ it('should insert a panel at a specific index', () => {
+ createRoot((dispose) => {
+ const solver = createResizeSolver({
+ direction: 'horizontal',
+ gutter: () => 4,
+ size: () => 1000,
+ panels: [
+ { id: 'A', minSize: 100, maxSize: Infinity },
+ { id: 'C', minSize: 100, maxSize: Infinity },
+ ],
+ });
+
+ expect(solver.order()).toEqual(['A', 'C']);
+
+ // Insert "B" at index 1 — should go between "A" and "C"
+ solver.addPanel({ id: 'B', minSize: 100, maxSize: Infinity }, 1);
+
+ expect(solver.order()).toEqual(['A', 'B', 'C']);
+
+ dispose();
+ });
+ });
+
+ it('should append when no index is given', () => {
+ createRoot((dispose) => {
+ const solver = createResizeSolver({
+ direction: 'horizontal',
+ gutter: () => 4,
+ size: () => 1000,
+ panels: [{ id: 'A', minSize: 100, maxSize: Infinity }],
+ });
+
+ solver.addPanel({ id: 'B', minSize: 100, maxSize: Infinity });
+
+ expect(solver.order()).toEqual(['A', 'B']);
+
+ dispose();
+ });
+ });
+
+ it('should not duplicate a panel that already exists', () => {
+ createRoot((dispose) => {
+ const solver = createResizeSolver({
+ direction: 'horizontal',
+ gutter: () => 4,
+ size: () => 1000,
+ panels: [{ id: 'A', minSize: 100, maxSize: Infinity }],
+ });
+
+ solver.addPanel({ id: 'A', minSize: 100, maxSize: Infinity }, 0);
+
+ expect(solver.order()).toEqual(['A']);
+
+ dispose();
+ });
+ });
+ });
+});
diff --git a/js/app/packages/core/component/Resize/solver.ts b/js/app/packages/core/component/Resize/solver.ts
index cd8cac0aaf..7ad282c336 100644
--- a/js/app/packages/core/component/Resize/solver.ts
+++ b/js/app/packages/core/component/Resize/solver.ts
@@ -258,7 +258,7 @@ export function createResizeSolver(params: {
const length = ids.length;
const nextLength = length + 1;
- let index = ndx && ndx < order().length ? ndx : order().length;
+ let index = ndx != null && ndx < order().length ? ndx : order().length;
// default is the "equal size" share
let incomingShare = 1 / nextLength;