diff --git a/src/app/comment-box/comment-box.component.ts b/src/app/comment-box/comment-box.component.ts index 0ffd0ab..e2fe1a2 100644 --- a/src/app/comment-box/comment-box.component.ts +++ b/src/app/comment-box/comment-box.component.ts @@ -117,6 +117,7 @@ export class CommentBoxComponent implements MatFormFieldControl, Control onFocusOut(event: FocusEvent) { if (!this._commentInputRef.nativeElement.contains(event.relatedTarget as Element)) { + this.cleanEmptyElements(this._commentInputRef.nativeElement); this.commentText = this._commentInputRef.nativeElement.innerHTML; this.touched = true; this.focused = false; @@ -220,6 +221,7 @@ export class CommentBoxComponent implements MatFormFieldControl, Control // open/close menu let focusedMentionElement = htmlElement.querySelector(`.mention.${Cursor.focusedClassName}`); + console.log(focusedMentionElement); if (focusedMentionElement) { // set offset for menu this.menuOffsetX = focusedMentionElement.offsetLeft; @@ -326,4 +328,9 @@ export class CommentBoxComponent implements MatFormFieldControl, Control if (focused) focused.remove(); } + + cleanEmptyElements(base: HTMLElement) { + base.querySelectorAll("span, div").forEach(el => el.textContent === "" && el.parentNode?.removeChild(el)) + base.innerHTML = base.innerHTML.replace(/class=""/g, ""); + } } \ No newline at end of file