Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Enable special character input, preserve line breaks using v-html
Browse files Browse the repository at this point in the history
  • Loading branch information
qaiswardag committed Sep 4, 2023
1 parent a2be9ac commit d68cb05
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/components/designer/editor-menu/editables/TextContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ watch(
<label class="myPrimaryInputLabel"> Text content </label>
<textarea
v-model="textContentVueModel"
v-html="textContentVueModel"
:value="designer.decodeHTML(textContentVueModel)"
rows="12"
class="myPrimaryTextArea"
@input="designer.changeText()"
@input="designer.changeText"
/>
</div>
</div>
Expand Down
30 changes: 18 additions & 12 deletions src/composables/Designer.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,22 +700,28 @@ class Designer {
}
}

async changeText() {
decodeHTML(html) {
const txt = document.createElement('textarea');
txt.innerHTML = html;
return txt.value;
}

async changeText(event) {
await this.nextTick;

if (this.getTextAreaVueModel.value !== null) {
let textContentElementClone = this.getTextAreaVueModel.value;
const textContentElementClone = event.target.value;

// Replace newline characters with <br> tags
textContentElementClone = textContentElementClone.replaceAll(
/\r?\n/g,
'<br>'
);
// Convert newline characters to <br> tags when saving
const textContentWithBr = textContentElementClone.replaceAll(
/\r?\n/g,
'<br>'
);

// text change
this.getElement.value.innerHTML = textContentElementClone;
this.store.commit('designer/setElement', this.getElement.value);
}
// Update both the displayed content and the model
this.textContentVueModel = textContentWithBr;
this.getElement.value.innerHTML = textContentWithBr;

this.store.commit('designer/setElement', this.getElement.value);
}

previewCurrentDesign() {
Expand Down

0 comments on commit d68cb05

Please sign in to comment.