Skip to content
Merged
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 @@ -35,6 +35,7 @@ export function TabsView() {
const activeWorkspaceId = activeWorkspace?.id;
const allTabs = useTabsStore((s) => s.tabs);
const addTab = useTabsStore((s) => s.addTab);
const addPane = useTabsStore((s) => s.addPane);
const renameTab = useTabsStore((s) => s.renameTab);
const reorderTabById = useTabsStore((s) => s.reorderTabById);
const activeTabIds = useTabsStore((s) => s.activeTabIds);
Expand All @@ -54,11 +55,24 @@ export function TabsView() {
[activeWorkspaceId, allTabs],
);

const activeTabId = activeWorkspaceId
? activeTabIds[activeWorkspaceId]
: null;

const handleAddTab = () => {
if (activeWorkspaceId) {
if (!activeWorkspaceId) return;

// If there's an active tab, add a pane to it instead of creating a new tab
if (activeTabId) {
const paneId = addPane(activeTabId);
// Fall back to creating a new tab if the active tab no longer exists
if (!paneId) {
addTab(activeWorkspaceId);
}
} else {
addTab(activeWorkspaceId);
setCommandOpen(false);
}
setCommandOpen(false);
};

const handleOpenPresetsSettings = () => {
Expand All @@ -69,15 +83,28 @@ export function TabsView() {
const handleSelectPreset = (preset: TerminalPreset) => {
if (!activeWorkspaceId) return;

// Pass preset options to addTab - Terminal component will read them from pane state
const { tabId } = addTab(activeWorkspaceId, {
const presetOptions = {
initialCommands: preset.commands,
initialCwd: preset.cwd || undefined,
});
name: preset.name || undefined,
};

// Rename the tab to the preset name
if (preset.name) {
renameTab(tabId, preset.name);
// If there's an active tab, add a pane to it instead of creating a new tab
if (activeTabId) {
const paneId = addPane(activeTabId, presetOptions);
// Fall back to creating a new tab if the active tab no longer exists
if (!paneId) {
const { tabId } = addTab(activeWorkspaceId, presetOptions);
if (preset.name) {
renameTab(tabId, preset.name);
}
}
} else {
const { tabId } = addTab(activeWorkspaceId, presetOptions);
// Rename the tab to the preset name only when creating a new tab
if (preset.name) {
renameTab(tabId, preset.name);
}
}

setCommandOpen(false);
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/renderer/stores/tabs/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,12 @@ export const useTabsStore = create<TabsStore>()(
},

// Pane operations
addPane: (tabId) => {
addPane: (tabId, options?: CreatePaneOptions) => {
const state = get();
const tab = state.tabs.find((t) => t.id === tabId);
if (!tab) return "";

const newPane = createPane(tabId);
const newPane = createPane(tabId, "terminal", options);

// Add pane to layout (append to the right)
const newLayout: MosaicNode<string> = {
Expand Down
4 changes: 3 additions & 1 deletion apps/desktop/src/renderer/stores/tabs/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MosaicBranch, MosaicNode } from "react-mosaic-component";
import type { BaseTab, BaseTabsState, Pane, PaneType } from "shared/tabs-types";
import type { CreatePaneOptions } from "./utils";

// Re-export shared types
export type { Pane, PaneType };
Expand All @@ -26,6 +27,7 @@ export interface TabsState extends Omit<BaseTabsState, "tabs"> {
export interface AddTabOptions {
initialCommands?: string[];
initialCwd?: string;
name?: string;
}
Comment on lines 27 to 31
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Consolidate duplicate type definitions.

AddTabOptions and CreatePaneOptions now have identical shapes (all three fields match: initialCommands?, initialCwd?, and name?). This duplication violates DRY principles and creates maintenance risk—if one interface changes, the other must be kept in sync manually.

Consider one of these approaches:

Option 1 (recommended): Use CreatePaneOptions directly

Remove AddTabOptions and use CreatePaneOptions everywhere:

-/**
- * Options for creating a tab with preset configuration
- */
-export interface AddTabOptions {
-	initialCommands?: string[];
-	initialCwd?: string;
-	name?: string;
-}
-
 /**
  * Actions available on the tabs store
  */
 export interface TabsStore extends TabsState {
 	// Tab operations
 	addTab: (
 		workspaceId: string,
-		options?: AddTabOptions,
+		options?: CreatePaneOptions,
 	) => { tabId: string; paneId: string };

Option 2: Make AddTabOptions extend CreatePaneOptions

If AddTabOptions may diverge in the future:

 /**
  * Options for creating a tab with preset configuration
  */
-export interface AddTabOptions {
-	initialCommands?: string[];
-	initialCwd?: string;
-	name?: string;
-}
+export interface AddTabOptions extends CreatePaneOptions {
+	// Add tab-specific options here if needed in the future
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export interface AddTabOptions {
initialCommands?: string[];
initialCwd?: string;
name?: string;
}
export interface AddTabOptions extends CreatePaneOptions {
// Add tab-specific options here if needed in the future
}
🤖 Prompt for AI Agents
In apps/desktop/src/renderer/stores/tabs/types.ts around lines 27-31,
AddTabOptions duplicates CreatePaneOptions; remove the duplicate by deleting the
AddTabOptions interface and replace its usages with CreatePaneOptions (or, if
you expect divergence, make AddTabOptions extend CreatePaneOptions instead).
Update all imports/usages across the codebase to reference CreatePaneOptions,
export CreatePaneOptions if not already exported, and run the TypeScript
build/tests to ensure no remaining references to AddTabOptions.


/**
Expand All @@ -50,7 +52,7 @@ export interface TabsStore extends TabsState {
updateTabLayout: (tabId: string, layout: MosaicNode<string>) => void;

// Pane operations
addPane: (tabId: string) => string;
addPane: (tabId: string, options?: CreatePaneOptions) => string;
removePane: (paneId: string) => void;
setFocusedPane: (tabId: string, paneId: string) => void;
markPaneAsUsed: (paneId: string) => void;
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/renderer/stores/tabs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const extractPaneIdsFromLayout = (
export interface CreatePaneOptions {
initialCommands?: string[];
initialCwd?: string;
name?: string;
}

/**
Expand All @@ -54,7 +55,7 @@ export const createPane = (
id,
tabId,
type,
name: "Terminal",
name: options?.name || "Terminal",
isNew: true,
initialCommands: options?.initialCommands,
initialCwd: options?.initialCwd,
Expand Down