@@ -23,6 +23,7 @@ import type {
23
23
CanvasesStateWithoutHistory ,
24
24
CanvasInpaintMaskState ,
25
25
CanvasMetadata ,
26
+ CanvasStateWithHistory ,
26
27
ChannelName ,
27
28
ChannelPoints ,
28
29
ControlLoRAConfig ,
@@ -136,7 +137,7 @@ const getInitialCanvasHistoryState = (id: string, name: string): StateWithHistor
136
137
137
138
const getInitialCanvasesState = ( ) : CanvasesStateWithoutHistory => {
138
139
const canvasId = getPrefixedId ( 'canvas' ) ;
139
- const canvasName = 'default' ;
140
+ const canvasName = getNextCanvasName ( [ ] ) ;
140
141
const canvas = getInitialCanvasState ( canvasId , canvasName ) ;
141
142
142
143
return {
@@ -155,6 +156,15 @@ const getInitialCanvasesHistoryState = (): CanvasesStateWithHistory => {
155
156
} ;
156
157
} ;
157
158
159
+ const getNextCanvasName = ( canvases : CanvasStateWithHistory [ ] ) : string => {
160
+ for ( let i = 1 ; ; i ++ ) {
161
+ const name = `Canvas-${ i } ` ;
162
+ if ( ! canvases . some ( ( c ) => c . present . name === name ) ) {
163
+ return name ;
164
+ }
165
+ }
166
+ } ;
167
+
158
168
const canvasesSlice = createSlice ( {
159
169
name : 'canvas' ,
160
170
initialState : getInitialCanvasesHistoryState ( ) ,
@@ -163,7 +173,7 @@ const canvasesSlice = createSlice({
163
173
reducer : ( state , action : PayloadAction < { id : string ; isSelected ?: boolean } > ) => {
164
174
const { id, isSelected } = action . payload ;
165
175
166
- const name = 'default' ;
176
+ const name = getNextCanvasName ( state . canvases ) ;
167
177
const canvas = getInitialCanvasHistoryState ( id , name ) ;
168
178
state . canvases . push ( canvas ) ;
169
179
0 commit comments