diff --git a/src/common/controllers/undo-redo-controller.ts b/src/common/controllers/undo-redo-controller.ts index df86df97b3..3f40069b1c 100644 --- a/src/common/controllers/undo-redo-controller.ts +++ b/src/common/controllers/undo-redo-controller.ts @@ -12,7 +12,7 @@ const UNDO_REDO_STACK_LIMIT = 75; */ export interface UndoRedoControllerConfig { stackLimit?: number; - currentConfig: () => ConfigType; + currentConfig: (itemBeingApplied?: ConfigType) => ConfigType; apply: (config: ConfigType) => void; } @@ -34,7 +34,9 @@ export class UndoRedoController implements ReactiveController { throw new Error("No apply function provided"); }; - private readonly _currentConfig: () => ConfigType = () => { + private readonly _currentConfig: ( + itemBeingApplied?: ConfigType + ) => ConfigType = () => { throw new Error("No currentConfig function provided"); }; @@ -105,8 +107,8 @@ export class UndoRedoController implements ReactiveController { if (this._undoStack.length === 0) { return; } - this._redoStack.push({ ...this._currentConfig() }); const config = this._undoStack.pop()!; + this._redoStack.push({ ...this._currentConfig(config) }); this._apply(config); this._host.requestUpdate(); } @@ -119,8 +121,8 @@ export class UndoRedoController implements ReactiveController { if (this._redoStack.length === 0) { return; } - this._undoStack.push({ ...this._currentConfig() }); const config = this._redoStack.pop()!; + this._undoStack.push({ ...this._currentConfig(config) }); this._apply(config); this._host.requestUpdate(); } diff --git a/src/panels/lovelace/hui-root.ts b/src/panels/lovelace/hui-root.ts index 5f4e9d3e5b..7ec18d2a01 100644 --- a/src/panels/lovelace/hui-root.ts +++ b/src/panels/lovelace/hui-root.ts @@ -151,8 +151,8 @@ class HUIRoot extends LitElement { private _undoRedoController = new UndoRedoController(this, { apply: (config) => this._applyUndoRedo(config), - currentConfig: () => ({ - location: this.route!.path, + currentConfig: (itemBeingApplied) => ({ + location: itemBeingApplied?.location ?? this.route!.path, config: this.lovelace!.rawConfig, }), });