@@ -72,6 +72,8 @@ export class ThemeEditor extends LitElement {
72
72
@state ( )
73
73
private effectiveTheme : ComponentTheme | null = null ;
74
74
75
+ private undoRedoListener ;
76
+
75
77
static get styles ( ) {
76
78
return css `
77
79
:host {
@@ -208,6 +210,19 @@ export class ThemeEditor extends LitElement {
208
210
this . historyActions = this . history . allowedActions ;
209
211
this . api . markAsUsed ( ) ;
210
212
213
+ this . undoRedoListener = ( evt : KeyboardEvent ) => {
214
+ const isZKey = evt . key === 'Z' || evt . key === 'z' ;
215
+ if ( isZKey && ( evt . ctrlKey || evt . metaKey ) && evt . shiftKey ) {
216
+ if ( this . historyActions ?. allowRedo ) {
217
+ this . handleRedo ( ) ;
218
+ }
219
+ } else if ( isZKey && ( evt . ctrlKey || evt . metaKey ) ) {
220
+ if ( this . historyActions ?. allowUndo ) {
221
+ this . handleUndo ( ) ;
222
+ }
223
+ }
224
+ }
225
+
211
226
// When the theme is updated due to HMR, remove optimistic updates from
212
227
// theme preview. Also refresh the base theme as default property values may
213
228
// have changed.
@@ -216,6 +231,8 @@ export class ThemeEditor extends LitElement {
216
231
this . refreshTheme ( ) ;
217
232
} ) ;
218
233
234
+ document . addEventListener ( 'keydown' , this . undoRedoListener ) ;
235
+
219
236
this . dispatchEvent ( new CustomEvent ( 'before-open' ) ) ;
220
237
}
221
238
@@ -237,8 +254,12 @@ export class ThemeEditor extends LitElement {
237
254
disconnectedCallback ( ) {
238
255
super . disconnectedCallback ( ) ;
239
256
this . removeElementHighlight ( this . context ?. component . element ) ;
257
+
240
258
componentOverlayManager . hideOverlay ( ) ;
241
259
componentOverlayManager . reset ( ) ;
260
+
261
+ document . removeEventListener ( 'keydown' , this . undoRedoListener ) ;
262
+
242
263
this . dispatchEvent ( new CustomEvent ( 'after-close' ) ) ;
243
264
}
244
265
0 commit comments