提交 8c2f3603 编写于 作者: B Benjamin Pasero

untitled - proper dirty reporting even when not resolved

上级 94421edf
......@@ -100,7 +100,7 @@ export class UntitledTextEditorModel extends BaseTextEditorModel implements IUnt
return this.labelService.getUriBasenameLabel(this.resource);
}
private dirty = false;
private dirty = this.hasAssociatedFilePath || !!this.initialValue;
private ignoreDirtyOnModelContentChange = false;
private versionId = 0;
......
......@@ -11,7 +11,6 @@ import { IUntitledTextEditorService, UntitledTextEditorService } from 'vs/workbe
import { workbenchInstantiationService, TestServiceAccessor } from 'vs/workbench/test/browser/workbenchTestServices';
import { snapshotToString } from 'vs/workbench/services/textfile/common/textfiles';
import { ModesRegistry, PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
import { IWorkingCopy } from 'vs/workbench/services/workingCopy/common/workingCopyService';
import { IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
import { Range } from 'vs/editor/common/core/range';
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
......@@ -120,9 +119,13 @@ suite('Untitled text editors', () => {
test('associated resource is dirty', async () => {
const service = accessor.untitledTextEditorService;
const file = URI.file(join('C:\\', '/foo/file.txt'));
const untitled = await service.resolve({ associatedResource: file });
assert.ok(untitled.hasAssociatedFilePath);
const untitled = instantiationService.createInstance(UntitledTextEditorInput, service.create({ associatedResource: file }));
assert.ok(untitled.isDirty());
const model = await untitled.resolve();
assert.ok(model.hasAssociatedFilePath);
assert.equal(untitled.isDirty(), true);
untitled.dispose();
......@@ -197,20 +200,14 @@ suite('Untitled text editors', () => {
const workingCopyService = accessor.workingCopyService;
const untitled = instantiationService.createInstance(UntitledTextEditorInput, service.create({ initialValue: 'Hello World' }));
let onDidChangeDirty: IWorkingCopy | undefined = undefined;
const listener = workingCopyService.onDidChangeDirty(copy => {
onDidChangeDirty = copy;
});
assert.ok(untitled.isDirty());
// dirty
const model = await untitled.resolve();
assert.ok(model.isDirty());
assert.equal(workingCopyService.dirtyCount, 1);
assert.equal(onDidChangeDirty, model);
untitled.dispose();
listener.dispose();
model.dispose();
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册