@@ -137,14 +137,17 @@ class SingleModelEditStackData {
137137
138138export class SingleModelEditStackElement implements IResourceUndoRedoElement {
139139
140- public model : ITextModel ;
140+ public model : ITextModel | URI ;
141141 private _data : SingleModelEditStackData | ArrayBuffer ;
142142
143143 public get type ( ) : UndoRedoElementType . Resource {
144144 return UndoRedoElementType . Resource ;
145145 }
146146
147147 public get resource ( ) : URI {
148+ if ( URI . isUri ( this . model ) ) {
149+ return this . model ;
150+ }
148151 return this . model . uri ;
149152 }
150153
@@ -157,7 +160,7 @@ export class SingleModelEditStackElement implements IResourceUndoRedoElement {
157160 this . _data = SingleModelEditStackData . create ( model , beforeCursorState ) ;
158161 }
159162
160- public setModel ( model : ITextModel ) : void {
163+ public setModel ( model : ITextModel | URI ) : void {
161164 this . model = model ;
162165 }
163166
@@ -178,6 +181,10 @@ export class SingleModelEditStackElement implements IResourceUndoRedoElement {
178181 }
179182
180183 public undo ( ) : void {
184+ if ( URI . isUri ( this . model ) ) {
185+ // don't have a model
186+ throw new Error ( `Invalid SingleModelEditStackElement` ) ;
187+ }
181188 if ( this . _data instanceof SingleModelEditStackData ) {
182189 this . _data = this . _data . serialize ( ) ;
183190 }
@@ -186,6 +193,10 @@ export class SingleModelEditStackElement implements IResourceUndoRedoElement {
186193 }
187194
188195 public redo ( ) : void {
196+ if ( URI . isUri ( this . model ) ) {
197+ // don't have a model
198+ throw new Error ( `Invalid SingleModelEditStackElement` ) ;
199+ }
189200 if ( this . _data instanceof SingleModelEditStackData ) {
190201 this . _data = this . _data . serialize ( ) ;
191202 }
@@ -211,7 +222,7 @@ export class MultiModelEditStackElement implements IWorkspaceUndoRedoElement {
211222 private readonly _editStackElementsMap : Map < string , SingleModelEditStackElement > ;
212223
213224 public get resources ( ) : readonly URI [ ] {
214- return this . _editStackElementsArr . map ( editStackElement => editStackElement . model . uri ) ;
225+ return this . _editStackElementsArr . map ( editStackElement => editStackElement . resource ) ;
215226 }
216227
217228 constructor (
@@ -223,13 +234,13 @@ export class MultiModelEditStackElement implements IWorkspaceUndoRedoElement {
223234 this . _editStackElementsArr = editStackElements . slice ( 0 ) ;
224235 this . _editStackElementsMap = new Map < string , SingleModelEditStackElement > ( ) ;
225236 for ( const editStackElement of this . _editStackElementsArr ) {
226- const key = uriGetComparisonKey ( editStackElement . model . uri ) ;
237+ const key = uriGetComparisonKey ( editStackElement . resource ) ;
227238 this . _editStackElementsMap . set ( key , editStackElement ) ;
228239 }
229240 }
230241
231- public setModel ( model : ITextModel ) : void {
232- const key = uriGetComparisonKey ( model . uri ) ;
242+ public setModel ( model : ITextModel | URI ) : void {
243+ const key = uriGetComparisonKey ( URI . isUri ( model ) ? model : model . uri ) ;
233244 if ( this . _editStackElementsMap . has ( key ) ) {
234245 this . _editStackElementsMap . get ( key ) ! . setModel ( model ) ;
235246 }
0 commit comments