Skip to content

Commit

Permalink
chore: refactor monaco's hot-reload
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Aug 4, 2024
1 parent 03bf56b commit a3895f5
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/lib/components/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@
onDestroy(() => editor?.dispose());
$: if (editor && source !== editor.getValue()) {
editor.setValue(source);
editor.updateOptions({ detectIndentation: false });
editor.updateOptions({ detectIndentation: true });
function reload(source: string, language = lang) {
if (language !== editor.getModel()!.getLanguageId()) {
core.editor.setModelLanguage(editor.getModel()!, language);
loadLanguage(language);
}
if (source !== editor.getValue()) {
editor.setValue(source);
editor.updateOptions({ detectIndentation: false });
editor.updateOptions({ detectIndentation: true });
}
}
$: if (editor && lang !== editor.getModel()!.getLanguageId()) {
loadLanguage(lang);
core.editor.setModelLanguage(editor.getModel()!, lang);
}
$: editor && reload(source, lang);
</script>

<div bind:this={container} class="h-full w-full overflow-hidden transition-opacity duration-400" class:op-0={!editor && firstLoad} />
Expand Down

0 comments on commit a3895f5

Please sign in to comment.