mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-20 15:56:35 +00:00
Merge pull request #13047 from piitaya/feat/ha-code-editor-autocomplete-icon-option
This commit is contained in:
commit
405cae9b5f
@ -2,6 +2,7 @@ import type {
|
|||||||
Completion,
|
Completion,
|
||||||
CompletionContext,
|
CompletionContext,
|
||||||
CompletionResult,
|
CompletionResult,
|
||||||
|
CompletionSource,
|
||||||
} from "@codemirror/autocomplete";
|
} from "@codemirror/autocomplete";
|
||||||
import type { EditorView, KeyBinding, ViewUpdate } from "@codemirror/view";
|
import type { EditorView, KeyBinding, ViewUpdate } from "@codemirror/view";
|
||||||
import { HassEntities } from "home-assistant-js-websocket";
|
import { HassEntities } from "home-assistant-js-websocket";
|
||||||
@ -48,6 +49,9 @@ export class HaCodeEditor extends ReactiveElement {
|
|||||||
@property({ type: Boolean, attribute: "autocomplete-entities" })
|
@property({ type: Boolean, attribute: "autocomplete-entities" })
|
||||||
public autocompleteEntities = false;
|
public autocompleteEntities = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean, attribute: "autocomplete-icons" })
|
||||||
|
public autocompleteIcons = false;
|
||||||
|
|
||||||
@property() public error = false;
|
@property() public error = false;
|
||||||
|
|
||||||
@state() private _value = "";
|
@state() private _value = "";
|
||||||
@ -160,17 +164,23 @@ export class HaCodeEditor extends ReactiveElement {
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!this.readOnly && this.autocompleteEntities && this.hass) {
|
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(
|
extensions.push(
|
||||||
this._loadedCodeMirror.autocompletion({
|
this._loadedCodeMirror.autocompletion({
|
||||||
override: [
|
override: completionSources,
|
||||||
this._entityCompletions.bind(this),
|
|
||||||
this._mdiCompletions.bind(this),
|
|
||||||
],
|
|
||||||
maxRenderedOptions: 10,
|
maxRenderedOptions: 10,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.codemirror = new this._loadedCodeMirror.EditorView({
|
this.codemirror = new this._loadedCodeMirror.EditorView({
|
||||||
state: this._loadedCodeMirror.EditorState.create({
|
state: this._loadedCodeMirror.EditorState.create({
|
||||||
|
@ -31,6 +31,7 @@ export class HaTemplateSelector extends LitElement {
|
|||||||
.readOnly=${this.disabled}
|
.readOnly=${this.disabled}
|
||||||
autofocus
|
autofocus
|
||||||
autocomplete-entities
|
autocomplete-entities
|
||||||
|
autocomplete-icons
|
||||||
@value-changed=${this._handleChange}
|
@value-changed=${this._handleChange}
|
||||||
dir="ltr"
|
dir="ltr"
|
||||||
></ha-code-editor>
|
></ha-code-editor>
|
||||||
|
@ -70,6 +70,7 @@ export class HaYamlEditor extends LitElement {
|
|||||||
.readOnly=${this.readOnly}
|
.readOnly=${this.readOnly}
|
||||||
mode="yaml"
|
mode="yaml"
|
||||||
autocomplete-entities
|
autocomplete-entities
|
||||||
|
autocomplete-icons
|
||||||
.error=${this.isValid === false}
|
.error=${this.isValid === false}
|
||||||
@value-changed=${this._onChange}
|
@value-changed=${this._onChange}
|
||||||
dir="ltr"
|
dir="ltr"
|
||||||
|
@ -60,6 +60,7 @@ class HaPanelDevMqtt extends LitElement {
|
|||||||
<ha-code-editor
|
<ha-code-editor
|
||||||
mode="jinja2"
|
mode="jinja2"
|
||||||
autocomplete-entities
|
autocomplete-entities
|
||||||
|
autocomplete-icons
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this.payload}
|
.value=${this.payload}
|
||||||
@value-changed=${this._handlePayload}
|
@value-changed=${this._handlePayload}
|
||||||
|
@ -133,6 +133,7 @@ class HaPanelDevTemplate extends LitElement {
|
|||||||
.error=${this._error}
|
.error=${this._error}
|
||||||
autofocus
|
autofocus
|
||||||
autocomplete-entities
|
autocomplete-entities
|
||||||
|
autocomplete-icons
|
||||||
@value-changed=${this._templateChanged}
|
@value-changed=${this._templateChanged}
|
||||||
dir="ltr"
|
dir="ltr"
|
||||||
></ha-code-editor>
|
></ha-code-editor>
|
||||||
|
@ -198,6 +198,7 @@ export abstract class HuiElementEditor<T> extends LitElement {
|
|||||||
mode="yaml"
|
mode="yaml"
|
||||||
autofocus
|
autofocus
|
||||||
autocomplete-entities
|
autocomplete-entities
|
||||||
|
autocomplete-icons
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${this.yaml}
|
.value=${this.yaml}
|
||||||
.error=${Boolean(this._errors)}
|
.error=${Boolean(this._errors)}
|
||||||
|
@ -92,6 +92,7 @@ class LovelaceFullConfigEditor extends LitElement {
|
|||||||
mode="yaml"
|
mode="yaml"
|
||||||
autofocus
|
autofocus
|
||||||
autocomplete-entities
|
autocomplete-entities
|
||||||
|
autocomplete-icons
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@value-changed=${this._yamlChanged}
|
@value-changed=${this._yamlChanged}
|
||||||
@editor-save=${this._handleSave}
|
@editor-save=${this._handleSave}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user