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) }