@@ -97,6 +97,19 @@ function generateLayoutFromGrid(size: [number, number]): Layout {
9797 } ;
9898}
9999
100+ function sameLayout ( a : Layout , b : Layout ) : boolean {
101+ return (
102+ a . direction === b . direction &&
103+ a . items . length === b . items . length &&
104+ a . items . every ( ( item , index ) => {
105+ const other = b . items [ index ] ;
106+ if ( item . type === 'slot' )
107+ return other . type === 'slot' && item . slotIndex === other . slotIndex ;
108+ return other . type === 'layout' && sameLayout ( item , other ) ;
109+ } )
110+ ) ;
111+ }
112+
100113function needsViewReplacement ( existingView : ViewInfo , nextView : ViewInfoInit ) {
101114 if ( existingView . type !== nextView . type ) return true ;
102115
@@ -121,7 +134,6 @@ export const useViewStore = defineStore('view', () => {
121134
122135 const defaultNamedLayoutEntries = Object . entries ( parsedDefaultLayouts ) ;
123136 const firstLayout = defaultNamedLayoutEntries [ 0 ] [ 1 ] ;
124- const firstLayoutName = defaultNamedLayoutEntries [ 0 ] [ 0 ] ;
125137
126138 const layout = ref < Layout > ( firstLayout . layout ) ;
127139 // which assigns view IDs to layout slots
@@ -133,7 +145,18 @@ export const useViewStore = defineStore('view', () => {
133145 ref < Record < string , { layout : Layout ; views : ViewInfoInit [ ] } > > (
134146 parsedDefaultLayouts
135147 ) ;
136- const currentLayoutName = ref < Maybe < string > > ( firstLayoutName ) ;
148+ // A named layout is current when switching to it would only rename views.
149+ const currentLayoutName = computed (
150+ ( ) =>
151+ Object . entries ( namedLayouts . value ) . find (
152+ ( [ , named ] ) =>
153+ sameLayout ( named . layout , layout . value ) &&
154+ named . views . every ( ( viewInit , index ) => {
155+ const view = viewByID [ layoutSlots . value [ index ] ] ;
156+ return view && ! needsViewReplacement ( view , viewInit ) ;
157+ } )
158+ ) ?. [ 0 ]
159+ ) ;
137160
138161 const isActiveViewMaximized = ref ( false ) ;
139162 const maximizedView = computed ( ( ) => {
@@ -242,14 +265,9 @@ export const useViewStore = defineStore('view', () => {
242265 function applyLayoutChange (
243266 newLayout : Layout ,
244267 options ?: {
245- layoutName ?: Maybe < string > ;
246268 updateSlots ?: ( viewCount : number ) => void ;
247269 }
248270 ) {
249- if ( options ?. layoutName !== undefined ) {
250- currentLayoutName . value = options . layoutName ;
251- }
252-
253271 isActiveViewMaximized . value = false ;
254272
255273 if ( options ?. updateSlots ) {
@@ -273,7 +291,6 @@ export const useViewStore = defineStore('view', () => {
273291 }
274292
275293 function setLayoutFromGrid ( gridSize : [ number , number ] ) {
276- currentLayoutName . value = null ;
277294 setLayout ( generateLayoutFromGrid ( gridSize ) ) ;
278295 }
279296
@@ -287,7 +304,6 @@ export const useViewStore = defineStore('view', () => {
287304 throw new Error ( `Named layout "${ name } " not found` ) ;
288305 }
289306 applyLayoutChange ( namedLayout . layout , {
290- layoutName : name ,
291307 updateSlots : ( ) => {
292308 namedLayout . views . forEach ( ( viewInit , index ) => {
293309 if ( index < layoutSlots . value . length ) {
@@ -359,7 +375,6 @@ export const useViewStore = defineStore('view', () => {
359375 function serialize ( stateFile : StateFile ) {
360376 const { manifest } = stateFile ;
361377 manifest . layout = layout . value ;
362- manifest . currentLayoutName = currentLayoutName . value ;
363378 manifest . activeView = activeView . value ;
364379 manifest . isActiveViewMaximized = isActiveViewMaximized . value ;
365380 manifest . layoutSlots = layoutSlots . value ;
@@ -368,8 +383,6 @@ export const useViewStore = defineStore('view', () => {
368383
369384 function deserializeLayout ( manifest : Manifest ) {
370385 if ( manifest . layout ) {
371- // Older scenes have unknown selection identity, even for matching panes.
372- currentLayoutName . value = manifest . currentLayoutName ;
373386 setLayout ( manifest . layout ) ;
374387 }
375388 setActiveView ( manifest . activeView ) ;
0 commit comments