@@ -2467,5 +2467,59 @@ define(function (require, exports, module) {
24672467 expect ( mark . length ) . toBe ( 0 ) ;
24682468 } ) ;
24692469 } ) ;
2470+ describe ( "Editor History undo redo" , function ( ) {
2471+
2472+ beforeEach ( function ( ) {
2473+ let jsContent = "const x=10;\n" +
2474+ "function print(val){\n" +
2475+ " console.log(val);\n" +
2476+ "}\n" +
2477+ "print(x);\n" +
2478+ "let str=`multi\n" +
2479+ "line`;" ;
2480+ createTestEditor ( jsContent , langNames . javascript . mode ) ;
2481+ } ) ;
2482+
2483+ it ( "should be able to get history" , function ( ) {
2484+ expect ( myEditor . getHistory ( ) . done . length ) . toBe ( 1 ) ;
2485+ expect ( myEditor . getHistory ( ) . undone . length ) . toBe ( 0 ) ;
2486+ myEditor . setSelection ( { line : 0 , ch : 0 } , { line : 0 , ch : 5 } ) ;
2487+ myEditor . replaceSelection ( "hello" , "around" ) ;
2488+ expect ( myEditor . getHistory ( ) . done . length ) . toBe ( 4 ) ;
2489+ expect ( myEditor . getHistory ( ) . undone . length ) . toBe ( 0 ) ;
2490+ } ) ;
2491+
2492+ it ( "should be able to create a history restore point and restore to that point" , function ( ) {
2493+ expect ( myEditor . getHistory ( ) . done . length ) . toBe ( 1 ) ;
2494+ expect ( myEditor . getHistory ( ) . undone . length ) . toBe ( 0 ) ;
2495+ myEditor . createHistoryRestorePoint ( "restore1" ) ;
2496+ myEditor . setSelection ( { line : 0 , ch : 0 } , { line : 0 , ch : 5 } ) ;
2497+ myEditor . replaceSelection ( "hello" , "around" ) ;
2498+ expect ( myEditor . getHistory ( ) . done . length ) . toBe ( 4 ) ;
2499+ expect ( myEditor . getHistory ( ) . undone . length ) . toBe ( 0 ) ;
2500+ myEditor . restoreHistoryPoint ( "restore1" ) ;
2501+ expect ( myEditor . getHistory ( ) . done . length ) . toBe ( 1 ) ;
2502+ expect ( myEditor . getHistory ( ) . undone . length ) . toBe ( 4 ) ;
2503+ } ) ;
2504+
2505+ it ( "should be able to set and restore multiple history points" , function ( ) {
2506+ expect ( myEditor . getHistory ( ) . done . length ) . toBe ( 1 ) ;
2507+ expect ( myEditor . getHistory ( ) . undone . length ) . toBe ( 0 ) ;
2508+ myEditor . setSelection ( { line : 0 , ch : 0 } , { line : 0 , ch : 5 } ) ;
2509+ myEditor . createHistoryRestorePoint ( "selectionRestore" ) ;
2510+ myEditor . replaceSelection ( "hello" , "around" ) ;
2511+ expect ( myEditor . getHistory ( ) . done . length ) . toBe ( 4 ) ;
2512+ myEditor . createHistoryRestorePoint ( "editRestore" ) ;
2513+ myEditor . replaceSelection ( "anotherEdit" , "around" ) ;
2514+ expect ( myEditor . getHistory ( ) . done . length ) . toBe ( 6 ) ;
2515+ expect ( myEditor . getHistory ( ) . undone . length ) . toBe ( 0 ) ;
2516+ expect ( myEditor . getSelectedText ( ) ) . toBe ( "anotherEdit" ) ;
2517+ // now restore one by one
2518+ myEditor . restoreHistoryPoint ( "editRestore" ) ;
2519+ expect ( myEditor . getSelectedText ( ) ) . toBe ( "hello" ) ;
2520+ myEditor . restoreHistoryPoint ( "selectionRestore" ) ;
2521+ expect ( myEditor . getSelectedText ( ) ) . toBe ( "const" ) ;
2522+ } ) ;
2523+ } ) ;
24702524 } ) ;
24712525} ) ;
0 commit comments