Skip to content

Commit

Permalink
Wrap code editor for template selector (home-assistant#21104)
Browse files Browse the repository at this point in the history
* Wrap code editor for template selector
  • Loading branch information
bramkragten authored Jun 17, 2024
1 parent 72f989e commit 27afe9e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/components/ha-code-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export class HaCodeEditor extends ReactiveElement {

@property({ type: Boolean }) public readOnly = false;

@property({ type: Boolean }) public linewrap = false;

@property({ type: Boolean, attribute: "autocomplete-entities" })
public autocompleteEntities = false;

Expand Down Expand Up @@ -134,6 +136,13 @@ export class HaCodeEditor extends ReactiveElement {
),
});
}
if (changedProps.has("linewrap")) {
transactions.push({
effects: this._loadedCodeMirror!.linewrapCompartment!.reconfigure(
this.linewrap ? this._loadedCodeMirror!.EditorView.lineWrapping : []
),
});
}
if (changedProps.has("_value") && this._value !== this.value) {
transactions.push({
changes: {
Expand Down Expand Up @@ -181,6 +190,9 @@ export class HaCodeEditor extends ReactiveElement {
this._loadedCodeMirror.readonlyCompartment.of(
this._loadedCodeMirror.EditorView.editable.of(!this.readOnly)
),
this._loadedCodeMirror.linewrapCompartment.of(
this.linewrap ? this._loadedCodeMirror.EditorView.lineWrapping : []
),
this._loadedCodeMirror.EditorView.updateListener.of(this._onUpdate),
];

Expand Down
1 change: 1 addition & 0 deletions src/components/ha-selector/ha-selector-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class HaTemplateSelector extends LitElement {
autocomplete-icons
@value-changed=${this._handleChange}
dir="ltr"
linewrap
></ha-code-editor>
${this.helper
? html`<ha-input-helper-text>${this.helper}</ha-input-helper-text>`
Expand Down
1 change: 1 addition & 0 deletions src/resources/codemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const langs = {

export const langCompartment = new Compartment();
export const readonlyCompartment = new Compartment();
export const linewrapCompartment = new Compartment();

export const tabKeyBindings: KeyBinding[] = [
{ key: "Tab", run: indentMore },
Expand Down

0 comments on commit 27afe9e

Please sign in to comment.