mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-15 14:00:38 +00:00
Expand pasting capabilities of automation editor (#26992)
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user