From ac49fc7abab9d774613601b0c317a38a83868a5a Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Thu, 2 Oct 2025 10:56:56 +0200 Subject: [PATCH] Support redo on Shift+CMD+Z (#27287) * Support redo on Shift+CMD+Z * Update redo shortcut for macOS to CMD+Shift+Z --- src/mixins/keyboard-shortcut-mixin.ts | 10 +++++----- .../config/automation/ha-automation-editor.ts | 14 +++++++++++--- src/panels/config/script/ha-script-editor.ts | 16 ++++++++++++---- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/mixins/keyboard-shortcut-mixin.ts b/src/mixins/keyboard-shortcut-mixin.ts index e0fd041454..ad4837ecc8 100644 --- a/src/mixins/keyboard-shortcut-mixin.ts +++ b/src/mixins/keyboard-shortcut-mixin.ts @@ -12,11 +12,11 @@ export const KeyboardShortcutMixin = >( class extends superClass { private _keydownEvent = (event: KeyboardEvent) => { const supportedShortcuts = this.supportedShortcuts(); + const key = event.shiftKey ? event.key.toUpperCase() : event.key; if ( (event.ctrlKey || event.metaKey) && - !event.shiftKey && !event.altKey && - event.key in supportedShortcuts + key in supportedShortcuts ) { // Only capture the event if the user is not focused on an input if (!canOverrideAlphanumericInput(event.composedPath())) { @@ -27,14 +27,14 @@ export const KeyboardShortcutMixin = >( return; } event.preventDefault(); - supportedShortcuts[event.key](); + supportedShortcuts[key](); return; } const supportedSingleKeyShortcuts = this.supportedSingleKeyShortcuts(); - if (event.key in supportedSingleKeyShortcuts) { + if (key in supportedSingleKeyShortcuts) { event.preventDefault(); - supportedSingleKeyShortcuts[event.key](); + supportedSingleKeyShortcuts[key](); } }; diff --git a/src/panels/config/automation/ha-automation-editor.ts b/src/panels/config/automation/ha-automation-editor.ts index 87f9ac92a2..deb5439e19 100644 --- a/src/panels/config/automation/ha-automation-editor.ts +++ b/src/panels/config/automation/ha-automation-editor.ts @@ -261,9 +261,16 @@ export class HaAutomationEditor extends UndoRedoMixin< ${this.hass.localize("ui.common.redo")} - (${shortcutIcon} - + - Y) + ( + ${isMac + ? html`${shortcutIcon} + + + Shift + + + Z` + : html`${shortcutIcon} + + + Y`}) ` : nothing} @@ -1196,6 +1203,7 @@ export class HaAutomationEditor extends UndoRedoMixin< Delete: () => this._deleteSelectedRow(), Backspace: () => this._deleteSelectedRow(), z: () => this.undo(), + Z: () => this.redo(), y: () => this.redo(), }; } diff --git a/src/panels/config/script/ha-script-editor.ts b/src/panels/config/script/ha-script-editor.ts index 566e6e18b1..aa22ff0731 100644 --- a/src/panels/config/script/ha-script-editor.ts +++ b/src/panels/config/script/ha-script-editor.ts @@ -212,10 +212,17 @@ export class HaScriptEditor extends UndoRedoMixin< ${this.hass.localize("ui.common.redo")} - - (${shortcutIcon} - + - Y) + ( + ${isMac + ? html`${shortcutIcon} + + + Shift + + + Z` + : html`${shortcutIcon} + + + Y`}) ` : nothing} @@ -1104,6 +1111,7 @@ export class HaScriptEditor extends UndoRedoMixin< Delete: () => this._deleteSelectedRow(), Backspace: () => this._deleteSelectedRow(), z: () => this.undo(), + Z: () => this.redo(), y: () => this.redo(), }; }