Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Aug 19, 2023
1 parent bf02822 commit cd42f5e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions war/src/main/js/components/textarea/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function init() {

async function generateEditorFromTextarea(textarea) {
const textareaLanguage = textarea.dataset.codeLanguage;
// const textareaOptions = textarea.dataset.codeOptions;
const language = languages.find((e) => e.alias.includes(textareaLanguage));
const loadedLanguage = await language.load();

Expand All @@ -26,13 +27,21 @@ async function generateEditorFromTextarea(textarea) {
extensions: [basicSetup, loadedLanguage.language, codeEditorTheme],
}),
});

textarea.parentNode.insertBefore(view.dom, textarea);
textarea.style.display = "none";
if (textarea.form) {
textarea.form.addEventListener("submit", () => {
textarea.value = view.state.doc.toString();
});
}

// create an Observer instance
const resizeObserver = new ResizeObserver((entries) => {
view.requestMeasure();
});
resizeObserver.observe(view.dom);

return view;
}

Expand Down

0 comments on commit cd42f5e

Please sign in to comment.