diff --git a/src/components/ha-code-editor.ts b/src/components/ha-code-editor.ts index ff1364a934..152e7a9a6f 100644 --- a/src/components/ha-code-editor.ts +++ b/src/components/ha-code-editor.ts @@ -2,6 +2,7 @@ import type { Completion, CompletionContext, CompletionResult, + CompletionSource, } from "@codemirror/autocomplete"; import type { EditorView, KeyBinding, ViewUpdate } from "@codemirror/view"; import { HassEntities } from "home-assistant-js-websocket"; @@ -48,6 +49,9 @@ export class HaCodeEditor extends ReactiveElement { @property({ type: Boolean, attribute: "autocomplete-entities" }) public autocompleteEntities = false; + @property({ type: Boolean, attribute: "autocomplete-icons" }) + public autocompleteIcons = false; + @property() public error = false; @state() private _value = ""; @@ -160,16 +164,22 @@ export class HaCodeEditor extends ReactiveElement { ), ]; - if (!this.readOnly && this.autocompleteEntities && this.hass) { - extensions.push( - this._loadedCodeMirror.autocompletion({ - override: [ - this._entityCompletions.bind(this), - this._mdiCompletions.bind(this), - ], - maxRenderedOptions: 10, - }) - ); + if (!this.readOnly) { + const completionSources: CompletionSource[] = []; + if (this.autocompleteEntities && this.hass) { + completionSources.push(this._entityCompletions.bind(this)); + } + if (this.autocompleteIcons) { + completionSources.push(this._mdiCompletions.bind(this)); + } + if (completionSources.length > 0) { + extensions.push( + this._loadedCodeMirror.autocompletion({ + override: completionSources, + maxRenderedOptions: 10, + }) + ); + } } this.codemirror = new this._loadedCodeMirror.EditorView({ diff --git a/src/components/ha-selector/ha-selector-template.ts b/src/components/ha-selector/ha-selector-template.ts index 1140ec83a7..0761473dd8 100644 --- a/src/components/ha-selector/ha-selector-template.ts +++ b/src/components/ha-selector/ha-selector-template.ts @@ -31,6 +31,7 @@ export class HaTemplateSelector extends LitElement { .readOnly=${this.disabled} autofocus autocomplete-entities + autocomplete-icons @value-changed=${this._handleChange} dir="ltr" > diff --git a/src/components/ha-yaml-editor.ts b/src/components/ha-yaml-editor.ts index a1f24f302f..bfa01b73b9 100644 --- a/src/components/ha-yaml-editor.ts +++ b/src/components/ha-yaml-editor.ts @@ -70,6 +70,7 @@ export class HaYamlEditor extends LitElement { .readOnly=${this.readOnly} mode="yaml" autocomplete-entities + autocomplete-icons .error=${this.isValid === false} @value-changed=${this._onChange} dir="ltr" diff --git a/src/panels/config/integrations/integration-panels/mqtt/mqtt-config-panel.ts b/src/panels/config/integrations/integration-panels/mqtt/mqtt-config-panel.ts index eaa03dc98f..e0f8f99319 100644 --- a/src/panels/config/integrations/integration-panels/mqtt/mqtt-config-panel.ts +++ b/src/panels/config/integrations/integration-panels/mqtt/mqtt-config-panel.ts @@ -60,6 +60,7 @@ class HaPanelDevMqtt extends LitElement { diff --git a/src/panels/lovelace/editor/hui-element-editor.ts b/src/panels/lovelace/editor/hui-element-editor.ts index e06cb7d83b..4f0483c659 100644 --- a/src/panels/lovelace/editor/hui-element-editor.ts +++ b/src/panels/lovelace/editor/hui-element-editor.ts @@ -198,6 +198,7 @@ export abstract class HuiElementEditor extends LitElement { mode="yaml" autofocus autocomplete-entities + autocomplete-icons .hass=${this.hass} .value=${this.yaml} .error=${Boolean(this._errors)} diff --git a/src/panels/lovelace/hui-editor.ts b/src/panels/lovelace/hui-editor.ts index ce6c15e99e..e59971d11f 100644 --- a/src/panels/lovelace/hui-editor.ts +++ b/src/panels/lovelace/hui-editor.ts @@ -92,6 +92,7 @@ class LovelaceFullConfigEditor extends LitElement { mode="yaml" autofocus autocomplete-entities + autocomplete-icons .hass=${this.hass} @value-changed=${this._yamlChanged} @editor-save=${this._handleSave}