Fixes #8096: Add options to TextEditor.edit that allows to control the undo/redo behaviour around the edit

This commit is contained in:
Alex Dima
2016-08-26 16:49:25 +02:00
parent 70ea0865e4
commit 05e9b96033
5 changed files with 40 additions and 19 deletions

View File

@@ -56,6 +56,12 @@ export enum TextEditorRevealType {
InCenterIfOutsideViewport = 2
}
export interface IApplyEditsOptions {
undoStopBefore: boolean;
undoStopAfter: boolean;
setEndOfLine: EndOfLine;
}
/**
* Text Editor that is permanently bound to the same model.
* It can be bound or not to a CodeEditor.
@@ -314,7 +320,7 @@ export class MainThreadTextEditor {
return editor.getControl() === this._codeEditor;
}
public applyEdits(versionIdCheck:number, edits:EditorCommon.ISingleEditOperation[], setEndOfLine:EndOfLine): boolean {
public applyEdits(versionIdCheck:number, edits:EditorCommon.ISingleEditOperation[], opts:IApplyEditsOptions): boolean {
if (this._model.getVersionId() !== versionIdCheck) {
console.warn('Model has changed in the meantime!');
// throw new Error('Model has changed in the meantime!');
@@ -323,9 +329,9 @@ export class MainThreadTextEditor {
}
if (this._codeEditor) {
if (setEndOfLine === EndOfLine.CRLF) {
if (opts.setEndOfLine === EndOfLine.CRLF) {
this._model.setEOL(EditorCommon.EndOfLineSequence.CRLF);
} else if (setEndOfLine === EndOfLine.LF) {
} else if (opts.setEndOfLine === EndOfLine.LF) {
this._model.setEOL(EditorCommon.EndOfLineSequence.LF);
}
@@ -338,9 +344,13 @@ export class MainThreadTextEditor {
};
});
this._codeEditor.pushUndoStop();
if (opts.undoStopBefore) {
this._codeEditor.pushUndoStop();
}
this._codeEditor.executeEdits('MainThreadTextEditor', transformedEdits);
this._codeEditor.pushUndoStop();
if (opts.undoStopAfter) {
this._codeEditor.pushUndoStop();
}
return true;
}