mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 01:36:49 +00:00
separate autocomplete options in ha-code-editor
This commit is contained in:
parent
b633067e5c
commit
830364721b
@ -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,16 +164,22 @@ export class HaCodeEditor extends ReactiveElement {
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!this.readOnly && this.autocompleteEntities && this.hass) {
|
if (!this.readOnly) {
|
||||||
extensions.push(
|
const completionSources: CompletionSource[] = [];
|
||||||
this._loadedCodeMirror.autocompletion({
|
if (this.autocompleteEntities && this.hass) {
|
||||||
override: [
|
completionSources.push(this._entityCompletions.bind(this));
|
||||||
this._entityCompletions.bind(this),
|
}
|
||||||
this._mdiCompletions.bind(this),
|
if (this.autocompleteIcons) {
|
||||||
],
|
completionSources.push(this._mdiCompletions.bind(this));
|
||||||
maxRenderedOptions: 10,
|
}
|
||||||
})
|
if (completionSources.length > 0) {
|
||||||
);
|
extensions.push(
|
||||||
|
this._loadedCodeMirror.autocompletion({
|
||||||
|
override: completionSources,
|
||||||
|
maxRenderedOptions: 10,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.codemirror = new this._loadedCodeMirror.EditorView({
|
this.codemirror = new this._loadedCodeMirror.EditorView({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user