Expand pasting capabilities of automation editor (#26992)

This commit is contained in:
Bram Kragten
2025-09-18 17:01:42 +02:00
committed by GitHub
parent 034afd1375
commit 283da74e2d
12 changed files with 181 additions and 19 deletions

View File

@@ -209,7 +209,7 @@ export class HaManualScriptEditor extends LitElement {
role="region"
aria-labelledby="sequence-heading"
.actions=${this.config.sequence || []}
.highlightedActions=${this._pastedConfig?.sequence || []}
.highlightedActions=${this._pastedConfig?.sequence}
@value-changed=${this._sequenceChanged}
@open-sidebar=${this._openSidebar}
@request-close-sidebar=${this._triggerCloseSidebar}
@@ -396,6 +396,20 @@ export class HaManualScriptEditor extends LitElement {
if (normalized) {
ev.preventDefault();
const keysPresent = Object.keys(normalized).filter(
(key) => ensureArray(normalized[key]).length
);
if (keysPresent.length === 1 && ["sequence"].includes(keysPresent[0])) {
// if only one type of element is pasted, insert under the currently active item
const previousConfig = { ...this.config };
if (this._tryInsertAfterSelected(normalized[keysPresent[0]])) {
this._previousConfig = previousConfig;
this._showPastedToastWithUndo();
return;
}
}
if (
this.dirty ||
ensureArray(this.config.sequence)?.length ||
@@ -546,6 +560,13 @@ export class HaManualScriptEditor extends LitElement {
fireEvent(this, "save-script");
}
private _tryInsertAfterSelected(config: Action | Action[]): boolean {
if (this._sidebarConfig && "insertAfter" in this._sidebarConfig) {
return this._sidebarConfig.insertAfter(config as any);
}
return false;
}
public expandAll() {
this._collapsableElements?.forEach((element) => {
element.expandAll();