Skip to content

Commit cdc2085

Browse files
committed
Fix location handling for undo/redo
1 parent fe50c12 commit cdc2085

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/common/controllers/undo-redo-controller.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const UNDO_REDO_STACK_LIMIT = 75;
1212
*/
1313
export 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
}

src/panels/lovelace/hui-root.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ class HUIRoot extends LitElement {
151151

152152
private _undoRedoController = new UndoRedoController<UndoStackItem>(this, {
153153
apply: (config) => this._applyUndoRedo(config),
154-
currentConfig: () => ({
155-
location: this.route!.path,
154+
currentConfig: (itemBeingApplied) => ({
155+
location: itemBeingApplied?.location ?? this.route!.path,
156156
config: this.lovelace!.rawConfig,
157157
}),
158158
});

0 commit comments

Comments
 (0)