@@ -12,7 +12,7 @@ const UNDO_REDO_STACK_LIMIT = 75;
1212 */
1313export interface UndoRedoControllerConfig < ConfigType > {
1414 stackLimit ?: number ;
15- currentConfig : ( ) => ConfigType ;
15+ currentConfig : ( itemBeingApplied ?: ConfigType ) => ConfigType ;
1616 apply : ( config : ConfigType ) => void ;
1717}
1818
@@ -34,7 +34,9 @@ export class UndoRedoController<ConfigType> implements ReactiveController {
3434 throw new Error ( "No apply function provided" ) ;
3535 } ;
3636
37- private readonly _currentConfig : ( ) => ConfigType = ( ) => {
37+ private readonly _currentConfig : (
38+ itemBeingApplied ?: ConfigType
39+ ) => ConfigType = ( ) => {
3840 throw new Error ( "No currentConfig function provided" ) ;
3941 } ;
4042
@@ -105,8 +107,8 @@ export class UndoRedoController<ConfigType> implements ReactiveController {
105107 if ( this . _undoStack . length === 0 ) {
106108 return ;
107109 }
108- this . _redoStack . push ( { ...this . _currentConfig ( ) } ) ;
109110 const config = this . _undoStack . pop ( ) ! ;
111+ this . _redoStack . push ( { ...this . _currentConfig ( config ) } ) ;
110112 this . _apply ( config ) ;
111113 this . _host . requestUpdate ( ) ;
112114 }
@@ -119,8 +121,8 @@ export class UndoRedoController<ConfigType> implements ReactiveController {
119121 if ( this . _redoStack . length === 0 ) {
120122 return ;
121123 }
122- this . _undoStack . push ( { ...this . _currentConfig ( ) } ) ;
123124 const config = this . _redoStack . pop ( ) ! ;
125+ this . _undoStack . push ( { ...this . _currentConfig ( config ) } ) ;
124126 this . _apply ( config ) ;
125127 this . _host . requestUpdate ( ) ;
126128 }
0 commit comments