@@ -22,7 +22,7 @@ export type BasicState = {
2222
2323export type BasicActions = {
2424 openCurrent : ( tab : TabInput ) => void ;
25- openNew : ( tab : TabInput ) => void ;
25+ openNew : ( tab : TabInput , options ?: { position ?: "start" | "end" } ) => void ;
2626 select : ( tab : Tab ) => void ;
2727 selectNext : ( ) => void ;
2828 selectPrev : ( ) => void ;
@@ -72,9 +72,9 @@ export const createBasicSlice = <
7272 view : tab . type ,
7373 } ) ;
7474 } ,
75- openNew : ( tab ) => {
75+ openNew : ( tab , options ) => {
7676 const { tabs, history, addRecentlyOpened } = get ( ) ;
77- set ( openTab ( tabs , tab , history , true ) ) ;
77+ set ( openTab ( tabs , tab , history , true , options ?. position ) ) ;
7878
7979 if ( tab . type === "sessions" ) {
8080 addRecentlyOpened ( tab . id ) ;
@@ -271,6 +271,7 @@ const openTab = <T extends BasicState & NavigationState>(
271271 newTab : TabInput ,
272272 history : Map < string , TabHistory > ,
273273 forceNewTab : boolean ,
274+ position ?: "start" | "end" ,
274275) : Partial < T > => {
275276 const tabWithDefaults : Tab = {
276277 ...getDefaultState ( newTab ) ,
@@ -317,7 +318,17 @@ const openTab = <T extends BasicState & NavigationState>(
317318 } else {
318319 activeTab = { ...tabWithDefaults , active : true , slotId : id ( ) } ;
319320 const deactivated = deactivateAll ( tabs ) ;
320- nextTabs = [ ...deactivated , activeTab ] ;
321+
322+ if ( position === "start" ) {
323+ const pinnedCount = deactivated . filter ( ( t ) => t . pinned ) . length ;
324+ nextTabs = [
325+ ...deactivated . slice ( 0 , pinnedCount ) ,
326+ activeTab ,
327+ ...deactivated . slice ( pinnedCount ) ,
328+ ] ;
329+ } else {
330+ nextTabs = [ ...deactivated , activeTab ] ;
331+ }
321332
322333 return updateWithHistory ( nextTabs , activeTab , history ) ;
323334 }
0 commit comments