diff --git a/src/vs/editor/test/common/services/modelService.test.ts b/src/vs/editor/test/common/services/modelService.test.ts index bc272b954ff80a8d55246a1a401e6416f07a079c..1bf482a2b42f597f728f0b10ff1f4a9017b05680 100644 --- a/src/vs/editor/test/common/services/modelService.test.ts +++ b/src/vs/editor/test/common/services/modelService.test.ts @@ -328,6 +328,36 @@ suite('ModelService', () => { assert.equal(model2.getValue(), 'text'); }); } + + test('does not maintain undo for same resource and different content', () => { + const resource = URI.parse('file://test.txt'); + + // create a model + const model1 = modelService.createModel('text', null, resource); + // make an edit + model1.pushEditOperations(null, [{ range: new Range(1, 5, 1, 5), text: '1' }], () => [new Selection(1, 5, 1, 5)]); + assert.equal(model1.getValue(), 'text1'); + // dispose it + modelService.destroyModel(resource); + + // create a new model with the same content + const model2 = modelService.createModel('text2', null, resource); + // undo + model2.undo(); + assert.equal(model2.getValue(), 'text2'); + }); + + test('setValue should clear undo stack', () => { + const resource = URI.parse('file://test.txt'); + + const model = modelService.createModel('text', null, resource); + model.pushEditOperations(null, [{ range: new Range(1, 5, 1, 5), text: '1' }], () => [new Selection(1, 5, 1, 5)]); + assert.equal(model.getValue(), 'text1'); + + model.setValue('text2'); + model.undo(); + assert.equal(model.getValue(), 'text2'); + }); }); function assertComputeEdits(lines1: string[], lines2: string[]): void {