@@ -55,9 +55,9 @@ export const createBasicSlice = <
5555 listenerStore . getState ( ) . live . status === "finalizing" ) ;
5656
5757 if ( currentActiveTab ?. pinned || isCurrentTabListening ) {
58- set ( openTab ( tabs , tab , history , false ) ) ;
59- } else {
6058 set ( openTab ( tabs , tab , history , true ) ) ;
59+ } else {
60+ set ( openTab ( tabs , tab , history , false ) ) ;
6161 }
6262
6363 if ( tab . type === "sessions" ) {
@@ -71,7 +71,7 @@ export const createBasicSlice = <
7171 } ,
7272 openNew : ( tab ) => {
7373 const { tabs, history, addRecentlyOpened } = get ( ) ;
74- set ( openTab ( tabs , tab , history , false ) ) ;
74+ set ( openTab ( tabs , tab , history , true ) ) ;
7575
7676 if ( tab . type === "sessions" ) {
7777 addRecentlyOpened ( tab . id ) ;
@@ -229,10 +229,6 @@ export const createBasicSlice = <
229229 } ,
230230} ) ;
231231
232- const removeDuplicates = ( tabs : Tab [ ] , newTab : Tab ) : Tab [ ] => {
233- return tabs . filter ( ( t ) => ! isSameTab ( t , newTab ) ) ;
234- } ;
235-
236232const setActiveFlags = ( tabs : Tab [ ] , activeTab : Tab ) : Tab [ ] => {
237233 return tabs . map ( ( t ) => ( { ...t , active : isSameTab ( t , activeTab ) } ) ) ;
238234} ;
@@ -258,7 +254,7 @@ const openTab = <T extends BasicState & NavigationState>(
258254 tabs : Tab [ ] ,
259255 newTab : TabInput ,
260256 history : Map < string , TabHistory > ,
261- replaceActive : boolean ,
257+ forceNewTab : boolean ,
262258) : Partial < T > => {
263259 const tabWithDefaults : Tab = {
264260 ...getDefaultState ( newTab ) ,
@@ -272,7 +268,13 @@ const openTab = <T extends BasicState & NavigationState>(
272268 const existingTab = tabs . find ( ( t ) => isSameTab ( t , tabWithDefaults ) ) ;
273269 const isNewTab = ! existingTab ;
274270
275- if ( replaceActive ) {
271+ if ( ! isNewTab ) {
272+ nextTabs = setActiveFlags ( tabs , existingTab ! ) ;
273+ const currentTab = { ...existingTab ! , active : true } ;
274+ return { tabs : nextTabs , currentTab, history } as Partial < T > ;
275+ }
276+
277+ if ( ! forceNewTab ) {
276278 const existingActiveIdx = tabs . findIndex ( ( t ) => t . active ) ;
277279 const currentActiveTab = tabs [ existingActiveIdx ] ;
278280
@@ -283,32 +285,20 @@ const openTab = <T extends BasicState & NavigationState>(
283285 slotId : currentActiveTab . slotId ,
284286 } ;
285287
286- nextTabs = tabs
287- . map ( ( t , idx ) => {
288- if ( idx === existingActiveIdx ) {
289- return activeTab ;
290- }
291- if ( isSameTab ( t , tabWithDefaults ) ) {
292- return null ;
293- }
294- return { ...t , active : false } ;
295- } )
296- . filter ( ( t ) : t is Tab => t !== null ) ;
288+ nextTabs = tabs . map ( ( t , idx ) => {
289+ if ( idx === existingActiveIdx ) {
290+ return activeTab ;
291+ }
292+ return { ...t , active : false } ;
293+ } ) ;
297294 } else {
298295 activeTab = { ...tabWithDefaults , active : true , slotId : id ( ) } ;
299- const withoutDuplicates = removeDuplicates ( tabs , tabWithDefaults ) ;
300- const deactivated = deactivateAll ( withoutDuplicates ) ;
296+ const deactivated = deactivateAll ( tabs ) ;
301297 nextTabs = [ ...deactivated , activeTab ] ;
302298 }
303299
304300 return updateWithHistory ( nextTabs , activeTab , history ) ;
305301 } else {
306- if ( ! isNewTab ) {
307- nextTabs = setActiveFlags ( tabs , existingTab ! ) ;
308- const currentTab = { ...existingTab ! , active : true } ;
309- return { tabs : nextTabs , currentTab, history } as Partial < T > ;
310- }
311-
312302 activeTab = { ...tabWithDefaults , active : true , slotId : id ( ) } ;
313303 const deactivated = deactivateAll ( tabs ) ;
314304 nextTabs = [ ...deactivated , activeTab ] ;
0 commit comments