From 51fdf52fa972f826b038fd25f9bbc9431dc7aee9 Mon Sep 17 00:00:00 2001 From: Aljaz Grilc Date: Wed, 3 Apr 2024 08:23:41 +0200 Subject: [PATCH] Make a function to copy textarea content to cloneDiv element --- service.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/service.js b/service.js index c19bf1e..9255150 100644 --- a/service.js +++ b/service.js @@ -716,6 +716,7 @@ class BesTAService { this.textAreaEl = textAreaEl this.textAreaEl.spellcheck = false this.cloneDiv = this.createCloneDiv(textAreaEl) + this.copyTAContent() this.service = BesService.register(this.cloneDiv, this) this.textAreaEl.addEventListener('input', () => this.handleInput()) this.textAreaEl.addEventListener('click', e => this.handleTAClick(e)) @@ -756,10 +757,9 @@ class BesTAService { /** * This function copies the text from the textarea to the clone div + * and creates div elements for each line of text in the textarea */ - handleInput() { - const customEvent = new InputEvent('beforeinput') - + copyTAContent() { const lines = this.textAreaEl.value.split('\n') this.cloneDiv.innerHTML = '' lines.forEach(line => { @@ -768,6 +768,14 @@ class BesTAService { if (line === '') divEl.innerHTML = ' ' this.cloneDiv.appendChild(divEl) }) + } + + /** + * This function copies the text from the textarea to the clone div + */ + handleInput() { + const customEvent = new InputEvent('beforeinput') + this.copyTAContent() this.cloneDiv.dispatchEvent(customEvent) }