From f5db1a8b2357844fd7cc93f90a97f7fd28994fe8 Mon Sep 17 00:00:00 2001 From: Hlars Date: Tue, 10 Dec 2024 10:06:44 +0100 Subject: [PATCH] improvements --- src/app/comment-box/comment-box.component.ts | 7 +++++++ 1 file changed, 7 insertions(+) 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