File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export default function ClosePaneButton() {
88 const [ isEnabled , setIsEnabled ] = useState ( false ) ;
99
1010 function refresh ( ) {
11- setIsEnabled ( ! ! ( noteContext && ! ! noteContext . mainNtxId ) ) ;
11+ setIsEnabled ( ! ! noteContext ) ;
1212 }
1313
1414 useTriliumEvent ( "noteContextReorder" , refresh ) ;
Original file line number Diff line number Diff line change @@ -100,9 +100,23 @@ export default class SplitNoteContainer extends FlexContainer<SplitNoteWidget> {
100100 }
101101
102102 async closeThisNoteSplitCommand ( { ntxId } : CommandListenerData < "closeThisNoteSplit" > ) {
103- if ( ntxId ) {
104- await appContext . tabManager . removeNoteContext ( ntxId ) ;
103+ if ( ! ntxId ) return ;
104+ const contexts = appContext . tabManager . noteContexts ;
105+
106+ const currentIndex = contexts . findIndex ( ( c ) => c . ntxId === ntxId ) ;
107+ if ( currentIndex === - 1 ) return ;
108+
109+ const isRemoveMainContext = ! contexts [ currentIndex ] . mainNtxId ;
110+ if ( isRemoveMainContext && currentIndex + 1 <= contexts . length ) {
111+ const ntxIds = contexts . map ( ( c ) => c . ntxId ) . filter ( ( c ) => ! ! c ) as string [ ] ;
112+ this . triggerCommand ( "noteContextReorder" , {
113+ ntxIdsInOrder : ntxIds ,
114+ oldMainNtxId : ntxId ,
115+ newMainNtxId : ntxIds [ currentIndex + 1 ]
116+ } ) ;
105117 }
118+
119+ await appContext . tabManager . removeNoteContext ( ntxId ) ;
106120 }
107121
108122 async moveThisNoteSplitCommand ( { ntxId, isMovingLeft } : CommandListenerData < "moveThisNoteSplit" > ) {
You can’t perform that action at this time.
0 commit comments