@@ -328,6 +328,36 @@ suite('ModelService', () => {
328328 assert . equal ( model2 . getValue ( ) , 'text' ) ;
329329 } ) ;
330330 }
331+
332+ test ( 'does not maintain undo for same resource and different content' , ( ) => {
333+ const resource = URI . parse ( 'file://test.txt' ) ;
334+
335+ // create a model
336+ const model1 = modelService . createModel ( 'text' , null , resource ) ;
337+ // make an edit
338+ model1 . pushEditOperations ( null , [ { range : new Range ( 1 , 5 , 1 , 5 ) , text : '1' } ] , ( ) => [ new Selection ( 1 , 5 , 1 , 5 ) ] ) ;
339+ assert . equal ( model1 . getValue ( ) , 'text1' ) ;
340+ // dispose it
341+ modelService . destroyModel ( resource ) ;
342+
343+ // create a new model with the same content
344+ const model2 = modelService . createModel ( 'text2' , null , resource ) ;
345+ // undo
346+ model2 . undo ( ) ;
347+ assert . equal ( model2 . getValue ( ) , 'text2' ) ;
348+ } ) ;
349+
350+ test ( 'setValue should clear undo stack' , ( ) => {
351+ const resource = URI . parse ( 'file://test.txt' ) ;
352+
353+ const model = modelService . createModel ( 'text' , null , resource ) ;
354+ model . pushEditOperations ( null , [ { range : new Range ( 1 , 5 , 1 , 5 ) , text : '1' } ] , ( ) => [ new Selection ( 1 , 5 , 1 , 5 ) ] ) ;
355+ assert . equal ( model . getValue ( ) , 'text1' ) ;
356+
357+ model . setValue ( 'text2' ) ;
358+ model . undo ( ) ;
359+ assert . equal ( model . getValue ( ) , 'text2' ) ;
360+ } ) ;
331361} ) ;
332362
333363function assertComputeEdits ( lines1 : string [ ] , lines2 : string [ ] ) : void {
0 commit comments