@@ -41,11 +41,11 @@ export class CustomEditorModel extends Disposable implements ICustomEditorModel
4141
4242 //#endregion
4343
44- protected readonly _onUndo = this . _register ( new Emitter < CustomEditorEdit > ( ) ) ;
45- readonly onUndo : Event < CustomEditorEdit > = this . _onUndo . event ;
44+ protected readonly _onUndo = this . _register ( new Emitter < readonly CustomEditorEdit [ ] > ( ) ) ;
45+ readonly onUndo = this . _onUndo . event ;
4646
47- protected readonly _onRedo = this . _register ( new Emitter < CustomEditorEdit > ( ) ) ;
48- readonly onRedo : Event < CustomEditorEdit > = this . _onRedo . event ;
47+ protected readonly _onRedo = this . _register ( new Emitter < readonly CustomEditorEdit [ ] > ( ) ) ;
48+ readonly onRedo = this . _onRedo . event ;
4949
5050 protected readonly _onWillSave = this . _register ( new Emitter < { waitUntil : ( until : Promise < any > ) => void } > ( ) ) ;
5151 readonly onWillSave = this . _onWillSave . event ;
@@ -72,11 +72,22 @@ export class CustomEditorModel extends Disposable implements ICustomEditorModel
7272 return true ;
7373 }
7474
75- public async revert ( options ?: IRevertOptions ) {
76- while ( this . _currentEditIndex > 0 ) {
77- this . undo ( ) ;
75+ public async revert ( _options ?: IRevertOptions ) {
76+ if ( this . _currentEditIndex === this . _savePoint ) {
77+ return true ;
7878 }
7979
80+ if ( this . _currentEditIndex >= this . _savePoint ) {
81+ const editsToUndo = this . _edits . slice ( this . _savePoint , this . _currentEditIndex ) ;
82+ this . _onUndo . fire ( editsToUndo . reverse ( ) ) ;
83+ } else if ( this . _currentEditIndex < this . _savePoint ) {
84+ const editsToRedo = this . _edits . slice ( this . _currentEditIndex , this . _savePoint ) ;
85+ this . _onRedo . fire ( editsToRedo ) ;
86+ }
87+
88+ this . _currentEditIndex = this . _savePoint ;
89+ this . _edits . splice ( this . _currentEditIndex + 1 , this . _edits . length - this . _currentEditIndex ) ;
90+ this . updateDirty ( ) ;
8091 return true ;
8192 }
8293
@@ -88,7 +99,7 @@ export class CustomEditorModel extends Disposable implements ICustomEditorModel
8899
89100 const undoneEdit = this . _edits [ this . _currentEditIndex ] ;
90101 -- this . _currentEditIndex ;
91- this . _onUndo . fire ( undoneEdit ) ;
102+ this . _onUndo . fire ( [ undoneEdit ] ) ;
92103
93104 this . updateDirty ( ) ;
94105 }
@@ -101,7 +112,7 @@ export class CustomEditorModel extends Disposable implements ICustomEditorModel
101112
102113 ++ this . _currentEditIndex ;
103114 const redoneEdit = this . _edits [ this . _currentEditIndex ] ;
104- this . _onRedo . fire ( redoneEdit ) ;
115+ this . _onRedo . fire ( [ redoneEdit ] ) ;
105116
106117 this . updateDirty ( ) ;
107118 }
0 commit comments