File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 13
13
var UndoManager = function ( ) {
14
14
this . $maxRev = 0 ;
15
15
this . $fromUndo = false ;
16
+ this . $undoDepth = Infinity ;
16
17
this . reset ( ) ;
17
18
} ;
18
19
@@ -36,6 +37,10 @@ var UndoManager = function() {
36
37
if ( ! this . $keepRedoStack ) this . $redoStack . length = 0 ;
37
38
if ( allowMerge === false || ! this . lastDeltas ) {
38
39
this . lastDeltas = [ ] ;
40
+ var undoStackLength = this . $undoStack . length ;
41
+ if ( undoStackLength > this . $undoDepth - 1 ) {
42
+ this . $undoStack . splice ( 0 , undoStackLength - this . $undoDepth + 1 ) ;
43
+ }
39
44
this . $undoStack . push ( this . lastDeltas ) ;
40
45
delta . id = this . $rev = ++ this . $maxRev ;
41
46
}
Original file line number Diff line number Diff line change @@ -369,6 +369,27 @@ module.exports = {
369
369
assert . equal ( editor . getValue ( ) , "" ) ;
370
370
editor . redo ( ) ;
371
371
assert . equal ( editor . getValue ( ) , "\n\n\n\n" ) ;
372
+ } ,
373
+ "test: limit possible undos amount" : function ( ) {
374
+ editor . setValue ( "" ) ;
375
+ undoManager . startNewGroup ( ) ;
376
+ editor . insert ( "a" ) ;
377
+ undoManager . startNewGroup ( ) ;
378
+ editor . insert ( "b" ) ;
379
+ undoManager . startNewGroup ( ) ;
380
+ editor . insert ( "c" ) ;
381
+ assert . equal ( undoManager . $undoStack . length , 3 ) ;
382
+
383
+ undoManager . $undoDepth = 1 ;
384
+ editor . setValue ( "" ) ;
385
+ undoManager . startNewGroup ( ) ;
386
+ editor . insert ( "a" ) ;
387
+ undoManager . startNewGroup ( ) ;
388
+ editor . insert ( "b" ) ;
389
+ undoManager . startNewGroup ( ) ;
390
+ editor . insert ( "c" ) ;
391
+ assert . equal ( undoManager . $undoStack [ 0 ] [ 0 ] . lines [ 0 ] , "c" ) ;
392
+ assert . equal ( undoManager . $undoStack . length , undoManager . $undoDepth ) ;
372
393
}
373
394
} ;
374
395
You can’t perform that action at this time.
0 commit comments