@@ -510,12 +510,17 @@ export default function DocumentMosaicWorkspace(props: Props) {
510510 return 'auto'
511511 }
512512 } )
513+ const insertSplitModeRef = useRef ( insertSplitMode )
513514 const focusRequestIdRef = useRef ( 0 )
514515 const saveTimerRef = useRef < number | null > ( null )
515516 const latestStateRef = useRef ( mosaicState )
516517 const shareLinkTokenRef = useRef ( shareLinkToken )
517518 const clearSavedLayoutRef = useRef ( false )
518519
520+ useEffect ( ( ) => {
521+ insertSplitModeRef . current = insertSplitMode
522+ } , [ insertSplitMode ] )
523+
519524 useEffect ( ( ) => {
520525 if ( typeof window === 'undefined' ) return
521526 try {
@@ -1070,9 +1075,19 @@ export default function DocumentMosaicWorkspace(props: Props) {
10701075 setMosaicState ( defaultState ( id ) )
10711076 } , [ id , isSingleDocShare ] )
10721077
1073- useShortcut ( 'tiles.split.direction.auto' , ( ) => setInsertSplitMode ( 'auto' ) )
1074- useShortcut ( 'tiles.split.direction.row' , ( ) => setInsertSplitMode ( 'row' ) )
1075- useShortcut ( 'tiles.split.direction.column' , ( ) => setInsertSplitMode ( 'column' ) )
1078+ const setInsertSplitModeWithToast = useCallback (
1079+ ( mode : InsertSplitMode ) => {
1080+ if ( insertSplitModeRef . current === mode ) return
1081+ setInsertSplitMode ( mode )
1082+ const label = mode === 'auto' ? 'Auto (BSP)' : mode === 'row' ? 'Horizontal' : 'Vertical'
1083+ toast . info ( `Tile insertion split: ${ label } ` )
1084+ } ,
1085+ [ setInsertSplitMode ] ,
1086+ )
1087+
1088+ useShortcut ( 'tiles.split.direction.auto' , ( ) => setInsertSplitModeWithToast ( 'auto' ) )
1089+ useShortcut ( 'tiles.split.direction.row' , ( ) => setInsertSplitModeWithToast ( 'row' ) )
1090+ useShortcut ( 'tiles.split.direction.column' , ( ) => setInsertSplitModeWithToast ( 'column' ) )
10761091 useShortcut ( 'tiles.swap.left' , ( ) => swapActiveTileByDirection ( 'left' ) , { preventDefault : true } )
10771092 useShortcut ( 'tiles.swap.right' , ( ) => swapActiveTileByDirection ( 'right' ) , { preventDefault : true } )
10781093 useShortcut ( 'tiles.swap.up' , ( ) => swapActiveTileByDirection ( 'up' ) , { preventDefault : true } )
@@ -1169,7 +1184,7 @@ export default function DocumentMosaicWorkspace(props: Props) {
11691184 )
11701185
11711186 const addPreviewTile = useCallback (
1172- ( docId : string ) => {
1187+ ( docId : string , splitMode ?: InsertSplitMode ) => {
11731188 const target = docId . trim ( )
11741189 if ( ! target ) return
11751190 if ( isSingleDocShare ) return
@@ -1182,7 +1197,12 @@ export default function DocumentMosaicWorkspace(props: Props) {
11821197 const exists = Object . values ( safe . tiles ) . some ( ( t ) => t . documentId === target && t . mode === 'preview' )
11831198 if ( exists ) return safe
11841199 const previewKey = makeTileKey ( )
1185- const nextLayout = insertLeafBsp ( safe . layout , previewKey , activeTileRef . current ?. tileKey , insertSplitMode )
1200+ const nextLayout = insertLeafBsp (
1201+ safe . layout ,
1202+ previewKey ,
1203+ activeTileRef . current ?. tileKey ,
1204+ splitMode ?? insertSplitMode ,
1205+ )
11861206 const nextTiles : Record < TileKey , TileSpec > = {
11871207 ...safe . tiles ,
11881208 [ previewKey ] : { mode : 'preview' , documentId : target } ,
@@ -1221,10 +1241,11 @@ export default function DocumentMosaicWorkspace(props: Props) {
12211241 useEffect ( ( ) => {
12221242 if ( isSingleDocShare ) return
12231243 const handler = ( event : Event ) => {
1224- const detail = ( event as CustomEvent < { documentId ?: string } > ) . detail
1244+ const detail = ( event as CustomEvent < { documentId ?: string ; splitMode ?: InsertSplitMode } > ) . detail
12251245 const documentId = typeof detail ?. documentId === 'string' ? detail . documentId . trim ( ) : ''
12261246 if ( ! documentId ) return
1227- addPreviewTile ( documentId )
1247+ const splitMode = detail ?. splitMode
1248+ addPreviewTile ( documentId , splitMode )
12281249 }
12291250 window . addEventListener ( OPEN_PREVIEW_TILE_EVENT , handler as EventListener )
12301251 return ( ) => window . removeEventListener ( OPEN_PREVIEW_TILE_EVENT , handler as EventListener )
0 commit comments