diff --git a/src/App.jsx b/src/App.jsx index 4c549719..3c929d40 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -67,29 +67,35 @@ function App() { const closeTab = (id) => { const newTerminals = terminals.filter((t) => t.id !== id); setTerminals(newTerminals); - setSplitTabIds(prev => prev.filter(tabId => tabId !== id)); if (activeTab === id) { setActiveTab(newTerminals[0]?.id || null); } }; - // Toggle split for a specific tab + // Toggle split for a terminal tab const toggleSplit = (id) => { - setSplitTabIds(prev => { - if (prev.includes(id)) { - return prev.filter(tabId => tabId !== id); - } else { - if (prev.length >= 1) return prev; // Limit to 1 split - return [...prev, id, activeTab].filter((tabId, index, self) => self.indexOf(tabId) === index); - } - }); + if (splitTabIds.length >= 3) return; // Prevent more than 2 tabs from splitting + + setSplitTabIds((prev) => + prev.includes(id) ? prev.filter((splitId) => splitId !== id) : [...prev, id] + ); + + if (splitTabIds.includes(id)) { + setSplitTabIds((prev) => prev.filter((splitId) => splitId !== id)); + } }; - // Get grid layout class based on split count - const getGridLayout = (count) => { - if (count === 1) return 'grid-cols-1'; - if (count === 2) return 'grid-cols-2'; - return 'grid-cols-1'; + // Determine the layout based on the number of split tabs + const getLayoutStyle = () => { + if (splitTabIds.length === 1) { + // Horizontal split (2 tabs: left-right) + return "flex flex-row h-full gap-4"; + } else if (splitTabIds.length > 1) { + // 2x2 Grid layout (4 tabs max), with evenly spaced rows + return "grid grid-cols-2 grid-rows-2 gap-4 h-full overflow-hidden"; + } + // No split, main tab takes the entire screen + return "flex flex-col h-full"; }; return ( @@ -153,48 +159,29 @@ function App() { {/* Terminal Views */} -
- {splitTabIds.length > 0 ? ( -
- {splitTabIds.map(id => { - const terminal = terminals.find(t => t.id === id); - return terminal ? ( -
- { - if (ref && !terminal.terminalRef) { - setTerminals(prev => prev.map(t => - t.id === terminal.id ? { ...t, terminalRef: ref } : t - )); - } - }} - /> -
- ) : null; - })} +
+ {terminals.map((terminal) => ( +
+ { + if (ref && !terminal.terminalRef) { + setTerminals((prev) => + prev.map((t) => + t.id === terminal.id + ? { ...t, terminalRef: ref } + : t + ) + ); + } + }} + />
- ) : ( -
- {terminals.find(t => t.id === activeTab) && ( -
- t.id === activeTab).hostConfig} - ref={(ref) => { - const terminal = terminals.find(t => t.id === activeTab); - if (ref && terminal && !terminal.terminalRef) { - setTerminals(prev => prev.map(t => - t.id === activeTab ? { ...t, terminalRef: ref } : t - )); - } - }} - /> -
- )} -
- )} + ))}
@@ -212,4 +199,4 @@ function App() { ); } -export default App; \ No newline at end of file +export default App; diff --git a/src/TabList.jsx b/src/TabList.jsx index c9d1a3c5..6ac09e53 100644 --- a/src/TabList.jsx +++ b/src/TabList.jsx @@ -2,74 +2,81 @@ import { Button, ButtonGroup } from "@mui/joy"; import PropTypes from "prop-types"; function TabList({ terminals, activeTab, setActiveTab, closeTab, toggleSplit, splitTabIds, theme }) { + const isSplitScreenActive = splitTabIds.length > 0; + return (
- {terminals.map((terminal, index) => ( -
- - - - - -
- ))} + {terminals.map((terminal, index) => { + const isActive = terminal.id === activeTab; + const isSplit = splitTabIds.includes(terminal.id); + + // Disable split screen button for the active tab (before and after splitting) + const isSplitButtonDisabled = isActive && !isSplitScreenActive || splitTabIds.length >= 3 && !isSplit; + + return ( +
+ + {/* Set active tab button */} + + {/* Split screen button */} + + {/* Close tab button */} + + +
+ ); + })}
); } @@ -84,4 +91,4 @@ TabList.propTypes = { theme: PropTypes.object.isRequired, }; -export default TabList; \ No newline at end of file +export default TabList;