@@ -360,15 +360,32 @@ export const copyTab = (app: App, tab: Tab) => {
360360 } ) ;
361361} ;
362362
363+ const getRootID = ( item : Tab ) => {
364+ if ( item . model instanceof Editor ) {
365+ return item . model . editor . protyle . block . rootID ;
366+ } else if ( ! item . model ) {
367+ const initTab = item . headElement . getAttribute ( "data-initdata" ) ;
368+ if ( initTab ) {
369+ try {
370+ const initTabData = JSON . parse ( initTab ) ;
371+ if ( initTabData && initTabData . instance === "Editor" && initTabData . rootId ) {
372+ return initTabData . rootId ;
373+ }
374+ } catch ( e ) {
375+ console . warn ( "Failed to parse tab init data:" , e ) ;
376+ }
377+ }
378+ }
379+ } ;
380+
381+
363382export const closeTabByType = ( tab : Tab , type : "closeOthers" | "closeAll" | "other" , tabs ?: Tab [ ] ) => {
364383 const rootIDs : string [ ] = [ ] ;
365384 if ( type === "closeOthers" ) {
366385 for ( let index = 0 ; index < tab . parent . children . length ; index ++ ) {
367386 const item = tab . parent . children [ index ] ;
368387 if ( item . id !== tab . id && ! item . headElement . classList . contains ( "item--pin" ) ) {
369- if ( item . model instanceof Editor ) {
370- rootIDs . push ( item . model . editor . protyle . block . rootID ) ;
371- }
388+ rootIDs . push ( getRootID ( item ) ) ;
372389 item . parent . removeTab ( item . id , true , false ) ;
373390 index -- ;
374391 }
@@ -377,9 +394,7 @@ export const closeTabByType = (tab: Tab, type: "closeOthers" | "closeAll" | "oth
377394 for ( let index = 0 ; index < tab . parent . children . length ; index ++ ) {
378395 const item = tab . parent . children [ index ] ;
379396 if ( ! item . headElement . classList . contains ( "item--pin" ) ) {
380- if ( item . model instanceof Editor ) {
381- rootIDs . push ( item . model . editor . protyle . block . rootID ) ;
382- }
397+ rootIDs . push ( getRootID ( item ) ) ;
383398 item . parent . removeTab ( item . id , true ) ;
384399 index -- ;
385400 }
0 commit comments