web/elements: fix race condition in codemirror

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-03 12:08:46 +02:00
parent a291063b9c
commit 94a5a6c4c0
1 changed files with 6 additions and 1 deletions

View File

@ -24,11 +24,15 @@ export class CodeMirrorTextarea extends LitElement {
editor?: CodeMirror.EditorFromTextArea;
_value?: string;
@property()
set value(v: string) {
if (v === null) return;
if (this.editor) {
this.editor.setValue(v);
} else {
this._value = v;
}
}
@ -70,6 +74,7 @@ export class CodeMirrorTextarea extends LitElement {
readOnly: this.readOnly,
autoRefresh: true,
lineWrapping: true,
value: this._value
});
this.editor.on("blur", () => {
this.editor?.save();
@ -77,6 +82,6 @@ export class CodeMirrorTextarea extends LitElement {
}
render(): TemplateResult {
return html`<textarea name=${ifDefined(this.name)}></textarea>`;
return html`<textarea name=${ifDefined(this.name)}>${ifDefined(this._value)}</textarea>`;
}
}