Skip to content

Commit

Permalink
make codemirror loading a bit more sync
Browse files Browse the repository at this point in the history
SQUASHED: AUTO-COMMIT-src-components-widgets-lively-code-mirror.js,
  • Loading branch information
JensLincke committed Apr 30, 2024
1 parent afa3ea8 commit 42f11f5
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/components/widgets/lively-code-mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export default class LivelyCodeMirror extends HTMLElement {
this.loadCSS("addon/hint/show-hint.css");
this.loadCSS("addon/lint/lint.css");
lively.loadCSSThroughDOM("CodeMirrorCSS", lively4url + "/src/components/widgets/lively-code-mirror.css");
self.__modulesAreLoaded__ = true
})();
return self.__codeMirrorLoadingPromise__;
}
Expand Down Expand Up @@ -230,12 +231,19 @@ export default class LivelyCodeMirror extends HTMLElement {
this.setAttribute(attr, value);
}
}

async connectedCallback() {
connectedCallback() {
if (this.isLoading || this.editor) return;
this.isLoading = true;
if ( self.__modulesAreLoaded__) {
this._connectedCallback()
} else {
LivelyCodeMirror.loadModules().then(() => this._connectedCallback())
}
}


_connectedCallback() {
this.root = this.shadowRoot; // used in code mirror to find current element
await LivelyCodeMirror.loadModules(); // lazy load modules...

if (this.textContent) {
var value = this.decodeHTML(this.textContent);
Expand All @@ -250,9 +258,10 @@ export default class LivelyCodeMirror extends HTMLElement {
this.dispatchEvent(event);
this["editor-loaded"] = true; // event can sometimes already be fired

await lively.sleep(0);
this.editor.refresh();
this.updateAExprDependencies();
lively.sleep(0).then(() => {
this.editor.refresh();
this.updateAExprDependencies();
})
}

async editorLoaded() {
Expand Down

0 comments on commit 42f11f5

Please sign in to comment.