improvements

This commit is contained in:
Hlars 2024-12-10 10:06:44 +01:00
parent 089150b88a
commit f5db1a8b23

View File

@ -117,6 +117,7 @@ export class CommentBoxComponent implements MatFormFieldControl<string>, Control
onFocusOut(event: FocusEvent) { onFocusOut(event: FocusEvent) {
if (!this._commentInputRef.nativeElement.contains(event.relatedTarget as Element)) { if (!this._commentInputRef.nativeElement.contains(event.relatedTarget as Element)) {
this.cleanEmptyElements(this._commentInputRef.nativeElement);
this.commentText = this._commentInputRef.nativeElement.innerHTML; this.commentText = this._commentInputRef.nativeElement.innerHTML;
this.touched = true; this.touched = true;
this.focused = false; this.focused = false;
@ -220,6 +221,7 @@ export class CommentBoxComponent implements MatFormFieldControl<string>, Control
// open/close menu // open/close menu
let focusedMentionElement = <HTMLElement>htmlElement.querySelector(`.mention.${Cursor.focusedClassName}`); let focusedMentionElement = <HTMLElement>htmlElement.querySelector(`.mention.${Cursor.focusedClassName}`);
console.log(focusedMentionElement);
if (focusedMentionElement) { if (focusedMentionElement) {
// set offset for menu // set offset for menu
this.menuOffsetX = focusedMentionElement.offsetLeft; this.menuOffsetX = focusedMentionElement.offsetLeft;
@ -326,4 +328,9 @@ export class CommentBoxComponent implements MatFormFieldControl<string>, Control
if (focused) if (focused)
focused.remove(); focused.remove();
} }
cleanEmptyElements(base: HTMLElement) {
base.querySelectorAll("span, div").forEach(el => el.textContent === "" && el.parentNode?.removeChild(el))
base.innerHTML = base.innerHTML.replace(/class=""/g, "");
}
} }