@@ -49,11 +49,21 @@ const Page = () => {
4949 setTabId ( newTabId ) ;
5050 } , [ userTabs , config ] ) ;
5151
52- const closeTab = useCallback ( ( ) => {
53- const newTabs = userTabs . filter ( ( t ) => t . tabId !== tabId ) ;
54- setUserTabs ( newTabs ) ;
55- setTabId ( _ . max ( newTabs . map ( ( t ) => t . tabId ) ) || 0 ) ;
56- } , [ userTabs , tabId ] ) ;
52+ const closeTab = useCallback (
53+ ( targetTabId : number ) => {
54+ const newTabs = userTabs . filter ( ( t ) => t . tabId !== targetTabId ) ;
55+ if ( newTabs . length === 0 ) {
56+ window . TerminalOne ?. app . quit ( ) ;
57+ } else {
58+ setUserTabs ( newTabs ) ;
59+ setTabId ( _ . max ( newTabs . map ( ( t ) => t . tabId ) ) || 0 ) ;
60+ }
61+ } ,
62+ [ userTabs ] ,
63+ ) ;
64+ const closeCurrentTab = useCallback ( ( ) => {
65+ closeTab ( tabId ) ;
66+ } , [ closeTab , tabId ] ) ;
5767
5868 const nextTab = useCallback ( ( ) => {
5969 const currentTabIndex = userTabs . findIndex ( ( t ) => t . tabId === tabId ) ;
@@ -126,7 +136,7 @@ const Page = () => {
126136
127137 useEffect ( ( ) => {
128138 commands . on ( 'createTab' , createTab ) ;
129- commands . on ( 'closeTab' , closeTab ) ;
139+ commands . on ( 'closeTab' , closeCurrentTab ) ;
130140 commands . on ( 'nextTab' , nextTab ) ;
131141 commands . on ( 'previousTab' , previousTab ) ;
132142 commands . on ( 'tab1' , switchToTab1 ) ;
@@ -141,7 +151,7 @@ const Page = () => {
141151
142152 return ( ) => {
143153 commands . off ( 'createTab' , createTab ) ;
144- commands . off ( 'closeTab' , closeTab ) ;
154+ commands . off ( 'closeTab' , closeCurrentTab ) ;
145155 commands . off ( 'nextTab' , nextTab ) ;
146156 commands . off ( 'previousTab' , previousTab ) ;
147157 commands . off ( 'tab1' , switchToTab1 ) ;
@@ -157,7 +167,7 @@ const Page = () => {
157167 } , [
158168 commands ,
159169 createTab ,
160- closeTab ,
170+ closeCurrentTab ,
161171 nextTab ,
162172 previousTab ,
163173 switchToTab1 ,
@@ -229,7 +239,7 @@ const Page = () => {
229239 < button
230240 className = "btn btn-ghost btn-square btn-xs opacity-50 hover:bg-transparent hover:opacity-100 ml-2"
231241 onClick = { ( ) => {
232- closeTab ( ) ;
242+ closeTab ( tabId ) ;
233243 } }
234244 >
235245 < FiX />
@@ -265,6 +275,9 @@ const Page = () => {
265275 key = { userTab . tabId }
266276 active = { tabId === userTab . tabId }
267277 tabId = { userTab . tabId }
278+ close = { ( ) => {
279+ closeTab ( userTab . tabId ) ;
280+ } }
268281 />
269282 ) ;
270283 } ) }
0 commit comments