Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("panelLayoutStore", () => {
usePanelLayoutStore.getState().initializeTask("task-1");
});

it("adds file tab to main panel", () => {
it("adds file tab to main panel by default", () => {
usePanelLayoutStore.getState().openFile("task-1", "src/App.tsx");

assertTabCount(getPanelTree("task-1"), "main-panel", 2);
Expand All @@ -73,6 +73,43 @@ describe("panelLayoutStore", () => {
]);
});

it("opens file in the focused panel", () => {
// Focus the terminal panel
usePanelLayoutStore
.getState()
.setFocusedPanel("task-1", "terminal-panel");

usePanelLayoutStore.getState().openFile("task-1", "src/App.tsx");

// File should open in terminal-panel (the focused panel), not main-panel
assertPanelLayout(getPanelTree("task-1"), [
{
panelId: "terminal-panel",
expectedTabs: ["shell", "file-src/App.tsx"],
activeTab: "file-src/App.tsx",
},
]);
assertTabCount(getPanelTree("task-1"), "main-panel", 1); // Only logs
});

it("falls back to main panel if focused panel does not exist", () => {
// Set focus to a non-existent panel
usePanelLayoutStore
.getState()
.setFocusedPanel("task-1", "non-existent-panel");

usePanelLayoutStore.getState().openFile("task-1", "src/App.tsx");

// File should fall back to main-panel
assertTabCount(getPanelTree("task-1"), "main-panel", 2);
assertPanelLayout(getPanelTree("task-1"), [
{
panelId: "main-panel",
expectedTabs: ["logs", "file-src/App.tsx"],
},
]);
});

it("sets newly opened file as active", () => {
usePanelLayoutStore.getState().openFile("task-1", "src/App.tsx");

Expand Down
25 changes: 15 additions & 10 deletions apps/array/src/renderer/features/panels/store/panelLayoutStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,22 @@ function openTab(
return { panelTree: updatedTree };
}

// Tab doesn't exist, add it to main panel
const mainPanel = getLeafPanel(
layout.panelTree,
DEFAULT_PANEL_IDS.MAIN_PANEL,
);
if (!mainPanel) return {};
// Tab doesn't exist, add it to the focused panel (or main panel as fallback)
const targetPanelId = layout.focusedPanelId ?? DEFAULT_PANEL_IDS.MAIN_PANEL;
let targetPanel = getLeafPanel(layout.panelTree, targetPanelId);

// Fall back to main panel if the focused panel doesn't exist or isn't a leaf
if (!targetPanel) {
targetPanel = getLeafPanel(
layout.panelTree,
DEFAULT_PANEL_IDS.MAIN_PANEL,
);
}
if (!targetPanel) return {};

const updatedTree = updateTreeNode(
layout.panelTree,
DEFAULT_PANEL_IDS.MAIN_PANEL,
(panel) => addNewTabToPanel(panel, tabId, true, asPreview),
const panelId = targetPanel.id;
const updatedTree = updateTreeNode(layout.panelTree, panelId, (panel) =>
addNewTabToPanel(panel, tabId, true, asPreview),
);

const metadata = updateMetadataForTab(layout, tabId, "add");
Expand Down