提交 56b067cf 编写于 作者: B Benjamin Pasero

adopt more snapshots

上级 0628d026
......@@ -82,6 +82,17 @@ export function createTextBufferFactoryFromStream(stream: IStringStream): TPromi
});
}
export function createTextBufferFactoryFromSnapshot(snapshot: ITextSnapshot): model.ITextBufferFactory {
let builder = createTextBufferBuilder();
let chunk: string;
while (typeof (chunk = snapshot.read()) === 'string') {
builder.acceptChunk(chunk);
}
return builder.finish();
}
export function createTextBuffer(value: string | model.ITextBufferFactory, defaultEOL: model.DefaultEndOfLine): model.ITextBuffer {
const factory = (typeof value === 'string' ? createTextBufferFactory(value) : value);
return factory.create(defaultEOL);
......
......@@ -31,6 +31,7 @@ import { FileEditorInput } from 'vs/workbench/parts/files/common/editors/fileEdi
import { IModelService } from 'vs/editor/common/services/modelService';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { SAVE_FILE_COMMAND_ID, REVERT_FILE_COMMAND_ID, SAVE_FILE_AS_COMMAND_ID, SAVE_FILE_AS_LABEL } from 'vs/workbench/parts/files/electron-browser/fileCommands';
import { createTextBufferFactoryFromSnapshot } from 'vs/editor/common/model/textModel';
export const CONFLICT_RESOLUTION_CONTEXT = 'saveConflictResolutionContext';
export const CONFLICT_RESOLUTION_SCHEME = 'conflictResolution';
......@@ -262,7 +263,7 @@ export const acceptLocalChangesCommand = (accessor: ServicesAccessor, resource:
resolverService.createModelReference(resource).then(reference => {
const model = reference.object as ITextFileEditorModel;
const localModelValue = model.getValue();
const localModelSnapshot = model.createSnapshot();
clearPendingResolveSaveConflictMessages(); // hide any previously shown message about how to use these actions
......@@ -270,7 +271,7 @@ export const acceptLocalChangesCommand = (accessor: ServicesAccessor, resource:
return model.revert().then(() => {
// Restore user value (without loosing undo stack)
modelService.updateModel(model.textEditorModel, localModelValue);
modelService.updateModel(model.textEditorModel, createTextBufferFactoryFromSnapshot(localModelSnapshot));
// Trigger save
return model.save().then(() => {
......
......@@ -32,6 +32,8 @@ import { Schemas } from 'vs/base/common/network';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IRevertOptions } from 'vs/platform/editor/common/editor';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { createTextBufferFactoryFromSnapshot } from 'vs/editor/common/model/textModel';
import { IModelService } from 'vs/editor/common/services/modelService';
export interface IBackupResult {
didBackup: boolean;
......@@ -73,7 +75,8 @@ export abstract class TextFileService implements ITextFileService {
private backupFileService: IBackupFileService,
private windowsService: IWindowsService,
private historyService: IHistoryService,
contextKeyService: IContextKeyService
contextKeyService: IContextKeyService,
private modelService: IModelService
) {
this.toUnbind = [];
......@@ -615,7 +618,7 @@ export abstract class TextFileService implements ITextFileService {
// take over encoding and model value from source model
targetModel.updatePreferredEncoding(sourceModel.getEncoding());
targetModel.textEditorModel.setValue(sourceModel.getValue());
this.modelService.updateModel(targetModel.textEditorModel, createTextBufferFactoryFromSnapshot(sourceModel.createSnapshot()));
// save model
return targetModel.save(options);
......
......@@ -30,6 +30,7 @@ import { IWindowsService, IWindowService } from 'vs/platform/windows/common/wind
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { mnemonicButtonLabel } from 'vs/base/common/labels';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IModelService } from 'vs/editor/common/services/modelService';
export class TextFileService extends AbstractTextFileService {
......@@ -41,6 +42,7 @@ export class TextFileService extends AbstractTextFileService {
@IInstantiationService instantiationService: IInstantiationService,
@IConfigurationService configurationService: IConfigurationService,
@IModeService private modeService: IModeService,
@IModelService modelService: IModelService,
@IWindowService private windowService: IWindowService,
@IEnvironmentService environmentService: IEnvironmentService,
@IMessageService messageService: IMessageService,
......@@ -49,7 +51,7 @@ export class TextFileService extends AbstractTextFileService {
@IHistoryService historyService: IHistoryService,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(lifecycleService, contextService, configurationService, fileService, untitledEditorService, instantiationService, messageService, environmentService, backupFileService, windowsService, historyService, contextKeyService);
super(lifecycleService, contextService, configurationService, fileService, untitledEditorService, instantiationService, messageService, environmentService, backupFileService, windowsService, historyService, contextKeyService, modelService);
}
public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> {
......
......@@ -180,9 +180,10 @@ export class TestTextFileService extends TextFileService {
@IBackupFileService backupFileService: IBackupFileService,
@IWindowsService windowsService: IWindowsService,
@IHistoryService historyService: IHistoryService,
@IContextKeyService contextKeyService: IContextKeyService
@IContextKeyService contextKeyService: IContextKeyService,
@IModelService modelService: IModelService
) {
super(lifecycleService, contextService, configurationService, fileService, untitledEditorService, instantiationService, messageService, TestEnvironmentService, backupFileService, windowsService, historyService, contextKeyService);
super(lifecycleService, contextService, configurationService, fileService, untitledEditorService, instantiationService, messageService, TestEnvironmentService, backupFileService, windowsService, historyService, contextKeyService, modelService);
}
public setPromptPath(path: string): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册